Camera.java revision e91b92546e645191f0fbcc681740d3c4081161dc
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
19788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvalaimport android.app.ActivityThread;
2010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant;
2110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant.SdkConstantType;
224f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.content.Context;
23a696f5d667227365da732481770767dcb330dd23Mathias Agopianimport android.graphics.ImageFormat;
244c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Liimport android.graphics.Point;
2530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Liimport android.graphics.Rect;
26fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennisimport android.graphics.SurfaceTexture;
274f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.media.IAudioService;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
294f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.IBinder;
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper;
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message;
324f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.RemoteException;
334f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.ServiceManager;
347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Allocation;
357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Element;
367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.RenderScript;
377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.RSIllegalArgumentException;
387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Type;
39bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.util.Log;
400a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selenimport android.text.TextUtils;
41bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.Surface;
42bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.SurfaceHolder;
43bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li
44bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.io.IOException;
45bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.lang.ref.WeakReference;
46bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.ArrayList;
477d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkinimport java.util.LinkedHashMap;
48bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.List;
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
51bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The Camera class is used to set image capture settings, start/stop preview,
52bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * snap pictures, and retrieve frames for encoding for video.  This class is a
53bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * client for the Camera service, which manages the actual camera hardware.
54df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
55bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To access the device camera, you must declare the
567478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * {@link android.Manifest.permission#CAMERA} permission in your Android
57df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * Manifest. Also be sure to include the
58df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
59bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * manifest element to declare camera features used by your application.
607478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * For example, if you use the camera and auto-focus feature, your Manifest
61df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * should include the following:</p>
62df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
63df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera" />
64df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
65df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
66bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To take pictures with this class, use the following steps:</p>
67bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
68bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
69341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * <li>Obtain an instance of Camera from {@link #open(int)}.
70bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
71bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Get existing (default) settings with {@link #getParameters()}.
72bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
73bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
74bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setParameters(Camera.Parameters)}.
75bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
76bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, call {@link #setDisplayOrientation(int)}.
77bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
78bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
79bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewDisplay(SurfaceHolder)}.  Without a surface, the camera
80bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * will be unable to start the preview.
81bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
82bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
83bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * preview surface.  Preview must be started before you can take a picture.
84bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
85bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
86bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
87bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * capture a photo.  Wait for the callbacks to provide the actual image data.
88bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
89bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>After taking a picture, preview display will have stopped.  To take more
90bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * photos, call {@link #startPreview()} again first.
91bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
92bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} to stop updating the preview surface.
93bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
94bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important:</b> Call {@link #release()} to release the camera for
95bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * use by other applications.  Applications should release the camera
96bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
97bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * it in {@link android.app.Activity#onResume()}).
98bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
99bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
100bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To quickly switch to video recording mode, use these steps:</p>
101bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
102bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
103bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Obtain and initialize a Camera and start preview as described above.
104bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
105bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #unlock()} to allow the media process to access the camera.
106bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
107bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
108bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * See {@link android.media.MediaRecorder} information about video recording.
109bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
110bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When finished recording, call {@link #reconnect()} to re-acquire
111bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * and re-lock the camera.
112bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
113bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, restart preview and take more photos or videos.
114bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
115bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
116bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
117bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
118bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This class is not thread-safe, and is meant for use from one event thread.
119bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Most long-running operations (preview, focus, photo capture, etc) happen
120bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * asynchronously and invoke callbacks as necessary.  Callbacks will be invoked
121341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * on the event thread {@link #open(int)} was called from.  This class's methods
122bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * must never be called from multiple threads at once.</p>
123bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
124df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
125df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * may have different hardware specifications, such as megapixel ratings and
126df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * auto-focus capabilities. In order for your application to be compatible with
1277478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * more devices, you should not make assumptions about the device camera
128df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * specifications.</p>
1296c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez *
1306c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <div class="special reference">
1316c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <h3>Developer Guides</h3>
1326c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <p>For more information about using cameras, read the
1336c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
1346c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * </div>
135b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala *
136b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
137b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala *             applications.
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
139b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala@Deprecated
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Camera {
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final String TAG = "Camera";
1429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
143d2c2929c94bec68741b85f4174e11307fb65157fWu-cheng Li    // These match the enums in frameworks/base/include/camera/Camera.h
144da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ERROR            = 0x001;
145da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_SHUTTER          = 0x002;
146da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_FOCUS            = 0x004;
147da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ZOOM             = 0x008;
148da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_PREVIEW_FRAME    = 0x010;
149da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_VIDEO_FRAME      = 0x020;
150da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_POSTVIEW_FRAME   = 0x040;
151da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
152da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
1534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
154bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li    private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
1559d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private static final int CAMERA_MSG_FOCUS_MOVE       = 0x800;
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1574838e338129e09a37b8c8ad5e44f85ec5cd3aea1Ashok Bhat    private long mNativeContext; // accessed by native methods
1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private EventHandler mEventHandler;
1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ShutterCallback mShutterCallback;
1609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mRawImageCallback;
1619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mJpegCallback;
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PreviewCallback mPreviewCallback;
1637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private boolean mUsingPreviewAllocation;
164e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    private PictureCallback mPostviewCallback;
1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private AutoFocusCallback mAutoFocusCallback;
1669d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private AutoFocusMoveCallback mAutoFocusMoveCallback;
1673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    private OnZoomChangeListener mZoomListener;
1684c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private FaceDetectionListener mFaceListener;
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ErrorCallback mErrorCallback;
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mOneShot;
17194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private boolean mWithBuffer;
1724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private boolean mFaceDetectionRunning = false;
173a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private final Object mAutoFocusCallbackLock = new Object();
1749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
175feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    private static final int NO_ERROR = 0;
176feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    private static final int EACCESS = -13;
177feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    private static final int ENODEV = -19;
1784c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int EBUSY = -16;
1794c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int EINVAL = -22;
1804c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int ENOSYS = -38;
1814c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int EUSERS = -87;
1824c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int EOPNOTSUPP = -95;
183feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
18510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new picture is taken by the camera, and the entry of
18610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * the picture has been added to the media store.
18710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the picture.
18810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
18910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
19010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
19110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
19210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
19310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new video is recorded by the camera, and the entry
19410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * of the video has been added to the media store.
19510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the video.
19610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
19710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
19810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
19910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
20010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
2014c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Camera HAL device API version 1.0
2024c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @hide
2034c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
2044c913801141163362dd5bb7c9784c83f69c11054Zhijun He    public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
2054c913801141163362dd5bb7c9784c83f69c11054Zhijun He
2064c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2074c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * A constant meaning the normal camera connect/open will be used.
2084c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
209a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
2104c913801141163362dd5bb7c9784c83f69c11054Zhijun He
2114c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2124c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Used to indicate HAL version un-specified.
2134c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
2144c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
215a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
2164c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2174c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Hardware face detection. It does not use much CPU.
2184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
219c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_HW = 0;
2204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
2214c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
222c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Software face detection. It uses some CPU.
2234c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
224c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_SW = 1;
2254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
2264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
227341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the number of physical cameras available on this device.
228e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
229e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public native static int getNumberOfCameras();
230e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
231e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
232341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the information about a particular camera.
233b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
234b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
2354f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
2364f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        _getCameraInfo(cameraId, cameraInfo);
2374f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
2384f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IAudioService audioService = IAudioService.Stub.asInterface(b);
2394f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        try {
2404f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            if (audioService.isCameraSoundForced()) {
2414f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // Only set this when sound is forced; otherwise let native code
2424f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // decide.
2434f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                cameraInfo.canDisableShutterSound = false;
2444f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
2454f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        } catch (RemoteException e) {
2464f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            Log.e(TAG, "Audio service is unavailable for queries");
2474f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
2484f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
2494f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
250b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
251b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
252b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * Information about a camera
253b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
254b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
255b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
256b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
257b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
258b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    public static class CameraInfo {
2597836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2607836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is opposite to that of the screen.
2617836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
262b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_BACK = 0;
2637836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li
2647836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2657836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is the same as that of the screen.
2667836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
267b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_FRONT = 1;
268b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
269b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
270464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * The direction that the camera faces. It should be
271b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
272b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2737836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int facing;
274b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
275b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
27632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The orientation of the camera image. The value is the angle that the
277b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * camera image needs to be rotated clockwise so it shows correctly on
27832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
279b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
28032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>For example, suppose a device has a naturally tall screen. The
2812fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * back-facing camera sensor is mounted in landscape. You are looking at
2822fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * the screen. If the top side of the camera sensor is aligned with the
2832fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the screen in natural orientation, the value should be
2842fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * 90. If the top side of a front-facing camera sensor is aligned with
28532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the right of the screen, the value should be 270.</p>
286b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
287b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * @see #setDisplayOrientation(int)
28869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setRotation(int)
28969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPreviewSize(int, int)
29069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPictureSize(int, int)
29169ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setJpegThumbnailSize(int, int)
292b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2937836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int orientation;
294f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala
295f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        /**
296f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>Whether the shutter sound can be disabled.</p>
297f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
298f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>On some devices, the camera shutter sound cannot be turned off
299f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * through {@link #enableShutterSound enableShutterSound}. This field
300f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * can be used to determine whether a call to disable the shutter sound
301f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * will succeed.</p>
302f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
303f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>If this field is set to true, then a call of
304f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * {@code enableShutterSound(false)} will be successful. If set to
305f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * false, then that call will fail, and the shutter sound will be played
306f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * when {@link Camera#takePicture takePicture} is called.</p>
307f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         */
308f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        public boolean canDisableShutterSound;
309b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    };
310b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
311b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
312a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * Creates a new Camera object to access a particular hardware camera. If
313a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * the same camera is opened by other applications, this will throw a
314a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * RuntimeException.
315a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *
316bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call {@link #release()} when you are done using the camera,
317bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * otherwise it will remain locked and be unavailable to other applications.
318bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
319341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * <p>Your application should only have one Camera object active at a time
320341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * for a particular hardware camera.
321bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
322bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callbacks from other methods are delivered to the event loop of the
323bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * thread which called open().  If this thread has no event loop, then
324bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callbacks are delivered to the main application event loop.  If there
325bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is no main application event loop, callbacks are not delivered.
326bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
327bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p class="caution"><b>Caution:</b> On some devices, this method may
328bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * take a long time to complete.  It is best to call this method from a
329bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
330bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * blocking the main application UI thread.
331bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
332341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * @param cameraId the hardware camera to access, between 0 and
333a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     *     {@link #getNumberOfCameras()}-1.
334bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @return a new Camera object, connected, locked and ready for use.
335a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * @throws RuntimeException if opening the camera fails (for example, if the
336a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     camera is in use by another process or device policy manager has
337a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     disabled the camera).
338facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
339e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
340e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public static Camera open(int cameraId) {
3417bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li        return new Camera(cameraId);
342e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    }
343e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
344e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
345a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * Creates a new Camera object to access the first back-facing camera on the
346a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * device. If the device does not have a back-facing camera, this returns
347a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * null.
3487836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li     * @see #open(int)
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public static Camera open() {
351a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        int numberOfCameras = getNumberOfCameras();
352a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        CameraInfo cameraInfo = new CameraInfo();
353a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        for (int i = 0; i < numberOfCameras; i++) {
354a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            getCameraInfo(i, cameraInfo);
355a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
3567bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li                return new Camera(i);
357a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            }
358a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        }
359a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        return null;
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3624c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
3634c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Creates a new Camera object to access a particular hardware camera with
3644c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * given hal API version. If the same camera is opened by other applications
3654c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * or the hal API version is not supported by this device, this will throw a
3664c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * RuntimeException.
3674c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
3684c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * You must call {@link #release()} when you are done using the camera,
3694c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * otherwise it will remain locked and be unavailable to other applications.
3704c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
3714c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Your application should only have one Camera object active at a time for
3724c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * a particular hardware camera.
3734c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
3744c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Callbacks from other methods are delivered to the event loop of the
3754c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * thread which called open(). If this thread has no event loop, then
3764c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * callbacks are delivered to the main application event loop. If there is
3774c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * no main application event loop, callbacks are not delivered.
3784c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p class="caution">
3794c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <b>Caution:</b> On some devices, this method may take a long time to
3804c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * complete. It is best to call this method from a worker thread (possibly
3814c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * using {@link android.os.AsyncTask}) to avoid blocking the main
3824c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * application UI thread.
3834c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
3844c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param cameraId The hardware camera to access, between 0 and
3854c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * {@link #getNumberOfCameras()}-1.
386a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @param halVersion The HAL API version this camera device to be opened as.
3874c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @return a new Camera object, connected, locked and ready for use.
388a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
389a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @throws IllegalArgumentException if the {@code halVersion} is invalid
390a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
3914c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @throws RuntimeException if opening the camera fails (for example, if the
3924c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * camera is in use by another process or device policy manager has disabled
3934c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * the camera).
394a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
3954c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
396a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @see #CAMERA_HAL_API_VERSION_1_0
3974c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
3984c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @hide
3994c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
4004c913801141163362dd5bb7c9784c83f69c11054Zhijun He    public static Camera openLegacy(int cameraId, int halVersion) {
401a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
402a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin            throw new IllegalArgumentException("Invalid HAL version " + halVersion);
403a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        }
404a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
4054c913801141163362dd5bb7c9784c83f69c11054Zhijun He        return new Camera(cameraId, halVersion);
4064c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
4074c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4084c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
4094c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Create a legacy camera object.
4104c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
4114c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param cameraId The hardware camera to access, between 0 and
4124c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * {@link #getNumberOfCameras()}-1.
4134c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param halVersion The HAL API version this camera device to be opened as.
4144c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
4154c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private Camera(int cameraId, int halVersion) {
416a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        int err = cameraInitVersion(cameraId, halVersion);
4174c913801141163362dd5bb7c9784c83f69c11054Zhijun He        if (checkInitErrors(err)) {
4184c913801141163362dd5bb7c9784c83f69c11054Zhijun He            switch(err) {
4194c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case EACCESS:
4204c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Fail to connect to camera service");
4214c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case ENODEV:
4224c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed");
4234c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case ENOSYS:
4244c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed because some methods"
4254c913801141163362dd5bb7c9784c83f69c11054Zhijun He                            + " are not implemented");
4264c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case EOPNOTSUPP:
4274c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed because the hal"
4284c913801141163362dd5bb7c9784c83f69c11054Zhijun He                            + " version is not supported by this device");
4294c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case EINVAL:
4304c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed because the input"
4314c913801141163362dd5bb7c9784c83f69c11054Zhijun He                            + " arugments are invalid");
4324c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case EBUSY:
4334c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed because the camera"
4344c913801141163362dd5bb7c9784c83f69c11054Zhijun He                            + " device was already opened");
4354c913801141163362dd5bb7c9784c83f69c11054Zhijun He                case EUSERS:
4364c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Camera initialization failed because the max"
4374c913801141163362dd5bb7c9784c83f69c11054Zhijun He                            + " number of camera devices were already opened");
4384c913801141163362dd5bb7c9784c83f69c11054Zhijun He                default:
4394c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    // Should never hit this.
4404c913801141163362dd5bb7c9784c83f69c11054Zhijun He                    throw new RuntimeException("Unknown camera error");
4414c913801141163362dd5bb7c9784c83f69c11054Zhijun He            }
4424c913801141163362dd5bb7c9784c83f69c11054Zhijun He        }
4434c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
4444c913801141163362dd5bb7c9784c83f69c11054Zhijun He
445a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private int cameraInitVersion(int cameraId, int halVersion) {
4464c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mShutterCallback = null;
4474c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mRawImageCallback = null;
4484c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mJpegCallback = null;
4494c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mPreviewCallback = null;
4504c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mPostviewCallback = null;
4514c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mUsingPreviewAllocation = false;
4524c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mZoomListener = null;
4534c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4544c913801141163362dd5bb7c9784c83f69c11054Zhijun He        Looper looper;
4554c913801141163362dd5bb7c9784c83f69c11054Zhijun He        if ((looper = Looper.myLooper()) != null) {
4564c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = new EventHandler(this, looper);
4574c913801141163362dd5bb7c9784c83f69c11054Zhijun He        } else if ((looper = Looper.getMainLooper()) != null) {
4584c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = new EventHandler(this, looper);
4594c913801141163362dd5bb7c9784c83f69c11054Zhijun He        } else {
4604c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = null;
4614c913801141163362dd5bb7c9784c83f69c11054Zhijun He        }
4624c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4634c913801141163362dd5bb7c9784c83f69c11054Zhijun He        String packageName = ActivityThread.currentPackageName();
4644c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4654c913801141163362dd5bb7c9784c83f69c11054Zhijun He        return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, packageName);
4664c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
4674c913801141163362dd5bb7c9784c83f69c11054Zhijun He
468a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private int cameraInitNormal(int cameraId) {
469a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
470a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    }
471a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
472a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    /**
473a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * Connect to the camera service using #connectLegacy
474a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
475a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * <p>
476a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * This acts the same as normal except that it will return
477a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * the detailed error code if open fails instead of
478a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * converting everything into {@code NO_INIT}.</p>
479a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
480a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
481a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
482a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @return a detailed errno error code, or {@code NO_ERROR} on success
483a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
484a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @hide
485a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     */
486a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    public int cameraInitUnspecified(int cameraId) {
487a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
488a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    }
489a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
490a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    /** used by Camera#open, Camera#open(int) */
4917bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li    Camera(int cameraId) {
492a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        int err = cameraInitNormal(cameraId);
493feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        if (checkInitErrors(err)) {
494feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            switch(err) {
495feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                case EACCESS:
496feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                    throw new RuntimeException("Fail to connect to camera service");
497feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                case ENODEV:
498feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                    throw new RuntimeException("Camera initialization failed");
499feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                default:
500feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                    // Should never hit this.
501feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk                    throw new RuntimeException("Unknown camera error");
502feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            }
503feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        }
504feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    }
505feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
506feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
507feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
508feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
509feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
510feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public static boolean checkInitErrors(int err) {
511feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        return err != NO_ERROR;
512feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    }
513feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
514feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
515feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
516feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
517feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public static Camera openUninitialized() {
518feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        return new Camera();
5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5211c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
5221c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * An empty Camera for testing purpose.
5231c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
5241c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    Camera() {
5251c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
5261c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
527a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    @Override
5289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    protected void finalize() {
529e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        release();
5309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5324c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private native final int native_setup(Object camera_this, int cameraId, int halVersion,
533788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala                                           String packageName);
534788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala
5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_release();
5369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disconnects and releases the Camera object resources.
540bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
541bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call this as soon as you're done with the Camera object.</p>
5429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public final void release() {
5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_release();
5454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
549bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unlocks the camera to allow another process to access it.
550bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Normally, the camera is locked to the process with an active Camera
551bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * object until {@link #release()} is called.  To allow rapid handoff
552bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * between processes, you can call this method to release the camera
553bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * temporarily for another process to use; once the other process is done
554bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you can call {@link #reconnect()} to reclaim the camera.
555bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
556bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This must be done before calling
55742419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
55842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * called after recording starts.
5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
560bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
562bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be unlocked.
5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
564bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void unlock();
5659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
567bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Re-locks the camera to prevent other processes from accessing it.
568bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera objects are locked by default unless {@link #unlock()} is
569bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called.  Normally {@link #reconnect()} is used instead.
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
57153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
57242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
57342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
57442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
57542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     *
576bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
577bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
578bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be re-locked (for
579bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
581ffe1cf251a4f8469695b8acfa37270684dc1b70cWu-cheng Li    public native final void lock();
5829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
584bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Reconnects to the camera service after another process used it.
585bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * After {@link #unlock()} is called, another process may use the
586bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera; when the process is done, you must reconnect to the camera,
587bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * which will re-acquire the lock and allow you to continue using the
588bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera.
5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
59053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
59142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
59242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
59342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
594bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
595bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
596bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
597bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if a connection cannot be re-established (for
598bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
600bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void reconnect() throws IOException;
6019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
603bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Sets the {@link Surface} to be used for live preview.
604fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
605fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface can be re-set
606fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * without harm.  Setting a preview surface will un-set any preview surface
607fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * texture that was set via {@link #setPreviewTexture}.
6089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
609bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The {@link SurfaceHolder} must already contain a surface when this
610bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method is called.  If you are using {@link android.view.SurfaceView},
611bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you will need to register a {@link SurfaceHolder.Callback} with
612bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
613bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
614bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling setPreviewDisplay() or starting preview.
615bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
616bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method must be called before {@link #startPreview()}.  The
617bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * one exception is that if the preview surface is not set (or set to null)
618bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * before startPreview() is called, then this method may be called once
619bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * with a non-null parameter to set the preview surface.  (This allows
620bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera setup and surface creation to happen in parallel, saving time.)
621bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * The preview surface may not otherwise change while preview is running.
6229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
623bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param holder containing the Surface on which to place the preview,
624bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to remove the preview surface
625bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if the method fails (for example, if the surface
626bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     is unavailable or unsuitable).
6279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
629b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        if (holder != null) {
630feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            setPreviewSurface(holder.getSurface());
631b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        } else {
632feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            setPreviewSurface((Surface)null);
633b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        }
6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
636feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
637feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
638feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
639feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public native final void setPreviewSurface(Surface surface) throws IOException;
6409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
642fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Sets the {@link SurfaceTexture} to be used for live preview.
643fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
644fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface texture can be
645fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * re-set without harm.  Setting a preview surface texture will un-set any
646fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview surface that was set via {@link #setPreviewDisplay}.
647fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
648fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * <p>This method must be called before {@link #startPreview()}.  The
649fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * one exception is that if the preview surface texture is not set (or set
650fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * to null) before startPreview() is called, then this method may be called
651fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * once with a non-null parameter to set the preview surface.  (This allows
652fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * camera setup and surface creation to happen in parallel, saving time.)
653fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * The preview surface texture may not otherwise change while preview is
654fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * running.
655fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
65632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
657e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * SurfaceTexture set as the preview texture have an unspecified zero point,
658e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * and cannot be directly compared between different cameras or different
659e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * instances of the same camera, or across multiple runs of the same
660e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * program.
661e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     *
662108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
663108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
664108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
665108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
666108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
667108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.graphics.SurfaceTexture
668108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.view.TextureView
669fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @param surfaceTexture the {@link SurfaceTexture} to which the preview
670fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     images are to be sent or null to remove the current preview surface
671fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture
672fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @throws IOException if the method fails (for example, if the surface
673fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture is unavailable or unsuitable).
674fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     */
675dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
676fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis
677fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis    /**
678bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to deliver copies of preview frames as
679bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * they are displayed.
680bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
681bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallback(Camera.PreviewCallback)
682bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
683bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
684bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startPreview()
685b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
686b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
687b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
6889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
689b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
6909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PreviewCallback
6919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
6929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
693bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as preview frames are displayed.  This callback is invoked
694341ff13689dfe822b598e626272ac2e80041b482Dan Egnor         * on the event thread {@link #open(int)} was called from.
6959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
696951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
697951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
698951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * for the arrangement of the pixel data in the preview callback
699951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * buffers.
700951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
701bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param data the contents of the preview frame in the format defined
702a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *  by {@link android.graphics.ImageFormat}, which can be queried
703df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         *  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
704da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         *  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
7059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             is never called, the default will be the YCbCr_420_SP
7069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             (NV21) format.
707bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param camera the Camera service object.
7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPreviewFrame(byte[] data, Camera camera);
7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
7119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
713bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts capturing and drawing preview frames to the screen.
714c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * Preview will not actually start until a surface is supplied
715c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * with {@link #setPreviewDisplay(SurfaceHolder)} or
716c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * {@link #setPreviewTexture(SurfaceTexture)}.
717bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
718bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
719bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
720bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
721bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
722bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * will be called when preview data becomes available.
7239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final void startPreview();
7259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
727bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops capturing and drawing preview frames to the surface, and
728bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * resets the camera for a future call to {@link #startPreview()}.
7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopPreview() {
7314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopPreview();
7324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
733664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang
734664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mShutterCallback = null;
735664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mRawImageCallback = null;
736664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mPostviewCallback = null;
737664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mJpegCallback = null;
738f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
739f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li            mAutoFocusCallback = null;
740f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        }
7419d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = null;
7424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
7434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
7444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopPreview();
7459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
7469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return current preview state.
7489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * FIXME: Unhide before release
7509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final boolean previewEnabled();
7539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
7549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
755108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame in addition
756bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to displaying them on the screen.  The callback will be repeatedly called
757bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * for as long as preview is active.  This method can be called at any time,
758108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * even while preview is live.  Any other preview callbacks are
759108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * overridden.</p>
760108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
761108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
762108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
763108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
765bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of each preview frame,
766bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
767108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewCallback(PreviewCallback cb) {
7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = cb;
7719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mOneShot = false;
77294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
7737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
7747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
7757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
776a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // Always use one-shot mode. We fake camera preview mode by
777a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // doing one-shot preview continuously.
77894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
7799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
782108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for the next preview frame in
783108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * addition to displaying it on the screen.  After one invocation, the
784108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * callback is cleared. This method can be called any time, even when
785108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview is live.  Any other preview callbacks are overridden.</p>
786108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
787108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
788108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
789108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
7909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
791bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the next preview frame,
792bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
793108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setOneShotPreviewCallback(PreviewCallback cb) {
79694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
79794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = true;
79894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
7997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
8007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
8017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
80294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
80394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    }
80494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
80594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
80694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
80794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
808108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame, using
809108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
810bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * displaying them on the screen.  The callback will be repeatedly called
811108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * for as long as preview is active and buffers are available.  Any other
812108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview callbacks are overridden.</p>
81394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
814bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The purpose of this method is to improve preview efficiency and frame
815bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * rate by allowing preview frame memory reuse.  You must call
816bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #addCallbackBuffer(byte[])} at some point -- before or after
817108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * calling this method -- or no callbacks will received.</p>
81894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
819108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>The buffer queue will be cleared if this method is called with a null
820bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
821108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
822108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * called.</p>
823108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
824108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
825108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
826108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
82794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
828bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the preview frame,
829bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks and clear the buffer queue.
830bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #addCallbackBuffer(byte[])
831108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
83294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
83394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
83494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
83594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = false;
83694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = true;
8377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
8387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
8397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
84094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, true);
8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
84394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
8443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Adds a pre-allocated buffer to the preview callback buffer queue.
8453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Applications can add one or more buffers to the queue. When a preview
846bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * frame arrives and there is still at least one available buffer, the
847bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * buffer will be used and removed from the queue. Then preview callback is
848bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * invoked with the buffer. If a frame arrives and there is no buffer left,
849bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the frame is discarded. Applications should add buffers back when they
850bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * finish processing the data in them.
851c10275abd6a494c93a025f683dde104a5d4f2793Wu-cheng Li     *
852951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>For formats besides YV12, the size of the buffer is determined by
853951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * multiplying the preview image width, height, and bytes per pixel. The
854951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * width and height can be read from
855951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
856951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
857951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * 8, using the image format from
858951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewFormat()}.
859951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
860951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
861951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * size can be calculated using the equations listed in
862951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#setPreviewFormat}.
86394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
864bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only necessary when
865e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
866bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallback(PreviewCallback)} or
867bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
868e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * are automatically allocated. When a supplied buffer is too small to
869e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * hold the preview frame data, preview callback will return null and
870e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * the buffer will be removed from the buffer queue.
87194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
872951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @param callbackBuffer the buffer to add to the queue. The size of the
873951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *   buffer must match the values described above.
8745b9bcda3a26e9b1f9b1eff28a2be8853d69614f0Wu-cheng Li     * @see #setPreviewCallbackWithBuffer(PreviewCallback)
87594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
876e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addCallbackBuffer(byte[] callbackBuffer)
877e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
878e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
879e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
880e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
881e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    /**
882e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Adds a pre-allocated buffer to the raw image callback buffer queue.
883e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Applications can add one or more buffers to the queue. When a raw image
884e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * frame arrives and there is still at least one available buffer, the
885e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * buffer will be used to hold the raw image data and removed from the
886e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * queue. Then raw image callback is invoked with the buffer. If a raw
887e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * image frame arrives but there is no buffer left, the frame is
888e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * discarded. Applications should add buffers back when they finish
889e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * processing the data in them by calling this method again in order
890e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * to avoid running out of raw image callback buffers.
891e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
892e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>The size of the buffer is determined by multiplying the raw image
893e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * width, height, and bytes per pixel. The width and height can be
894e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
895e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * can be computed from
896e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
897e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
898e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
899e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>This method is only necessary when the PictureCallbck for raw image
900e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * is used while calling {@link #takePicture(Camera.ShutterCallback,
901e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
902e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
90332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Please note that by calling this method, the mode for
90432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * application-managed callback buffers is triggered. If this method has
90532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * never been called, null will be returned by the raw image callback since
90632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * there is no image callback buffer available. Furthermore, When a supplied
90732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * buffer is too small to hold the raw image data, raw image callback will
90832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * return null and the buffer will be removed from the buffer queue.
909e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
910e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @param callbackBuffer the buffer to add to the raw image callback buffer
911e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     queue. The size should be width * height * (bits per pixel) / 8. An
912e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     null callbackBuffer will be ignored and won't be added to the queue.
913e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
914e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @see #takePicture(Camera.ShutterCallback,
915e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
916e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
917e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@hide}
918e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     */
919e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
920e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
921e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
922e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
923e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
924e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
925e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
926e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
927e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
928e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType != CAMERA_MSG_RAW_IMAGE) {
929e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            throw new IllegalArgumentException(
930e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                            "Unsupported message type: " + msgType);
931e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
932e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
933e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, msgType);
934e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
935e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
936e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void _addCallbackBuffer(
937e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                                byte[] callbackBuffer, int msgType);
9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
9407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Create a {@link android.renderscript RenderScript}
9417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation Allocation} to use as a
9427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * destination of preview callback frames. Use
9437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
9447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the created Allocation as a destination for camera preview frames.</p>
9457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
9467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>The Allocation will be created with a YUV type, and its contents must
9477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
9487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * accessor methods. Its size will be based on the current
9497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#getPreviewSize preview size} configured for this
9507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * camera.</p>
9517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
9527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param rs the RenderScript context for this Allocation.
9537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param usage additional usage flags to set for the Allocation. The usage
9547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
9557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   be set on the created Allocation, but additional flags may be provided
9567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   here.
9577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @return a new YUV-type Allocation with dimensions equal to the current
9587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview size.
9597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws RSIllegalArgumentException if the usage flags are not compatible
9607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   with an YUV Allocation.
9617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackAllocation
9627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
9637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
9647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final Allocation createPreviewAllocation(RenderScript rs, int usage)
9657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws RSIllegalArgumentException {
9667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Parameters p = getParameters();
9677005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Size previewSize = p.getPreviewSize();
9687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Type.Builder yuvBuilder = new Type.Builder(rs,
9697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                Element.createPixel(rs,
9707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataType.UNSIGNED_8,
9717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataKind.PIXEL_YUV));
9727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // Use YV12 for wide compatibility. Changing this requires also
9737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // adjusting camera service's format selection.
9747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setYuvFormat(ImageFormat.YV12);
9757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setX(previewSize.width);
9767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setY(previewSize.height);
9777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
9787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
9797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                usage | Allocation.USAGE_IO_INPUT);
9807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
9817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        return a;
9827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
9837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
9847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
9857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Set an {@link android.renderscript.Allocation Allocation} as the
9867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * target of preview callback data. Use this method for efficient processing
9877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * of camera preview data with RenderScript. The Allocation must be created
9887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * with the {@link #createPreviewAllocation createPreviewAllocation }
9897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * method.</p>
9907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
9917005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Setting a preview allocation will disable any active preview callbacks
9927005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * set by {@link #setPreviewCallback setPreviewCallback} or
9937005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
9947005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * vice versa. Using a preview allocation still requires an active standard
9957005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview target to be set, either with
9967005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewTexture setPreviewTexture} or
9977005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewDisplay setPreviewDisplay}.</p>
9987005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
9997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To be notified when new frames are available to the Allocation, use
10007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
10017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * update the frame currently accessible from the Allocation to the latest
10027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview frame, call
10037005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
10047005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10057005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To disable preview into the Allocation, call this method with a
10067005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@code null} parameter.</p>
10077005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10087005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Once a preview allocation is set, the preview size set by
10097005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
10107005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * you wish to change the preview size, first remove the preview allocation
10117005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * by calling {@code setPreviewCallbackAllocation(null)}, then change the
10127005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview size, create a new preview Allocation with
10137005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
10147005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the new preview callback allocation target.</p>
10157005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10167005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
10177005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
10187005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
10197005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10207005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param previewAllocation the allocation to use as destination for preview
10217005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IOException if configuring the camera to use the Allocation for
10227005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview fails.
10237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IllegalArgumentException if the Allocation's dimensions or other
10247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   parameters don't meet the requirements.
10257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #createPreviewAllocation
10267005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallback
10277005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackWithBuffer
10287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
10297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
10307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final void setPreviewCallbackAllocation(Allocation previewAllocation)
10317005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws IOException {
10327005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Surface previewSurface = null;
10337005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (previewAllocation != null) {
10347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Parameters p = getParameters();
10357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Size previewSize = p.getPreviewSize();
10367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewSize.width != previewAllocation.getType().getX() ||
10377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height != previewAllocation.getType().getY()) {
10387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
10397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation dimensions don't match preview dimensions: " +
10407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is " +
10417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getX() +
10427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ", " +
10437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getY() +
10447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ". Preview is " + previewSize.width + ", " +
10457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height);
10467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
10477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if ((previewAllocation.getUsage() &
10487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                             Allocation.USAGE_IO_INPUT) == 0) {
10497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
10507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation usage does not include USAGE_IO_INPUT");
10517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
10527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewAllocation.getType().getElement().getDataKind() !=
10537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     Element.DataKind.PIXEL_YUV) {
10547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
10557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is not of a YUV type");
10567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
10577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             previewSurface = previewAllocation.getSurface();
10587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = true;
10597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         } else {
10607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = false;
10617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         }
10627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         setPreviewCallbackSurface(previewSurface);
10637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
10647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
10657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private native final void setPreviewCallbackSurface(Surface s);
10667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
10679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class EventHandler extends Handler
10689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
1069a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        private final Camera mCamera;
10709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public EventHandler(Camera c, Looper looper) {
10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            super(looper);
10739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mCamera = c;
10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
10759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        @Override
10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void handleMessage(Message msg) {
10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(msg.what) {
1079c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_SHUTTER:
10809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mShutterCallback != null) {
10819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mShutterCallback.onShutter();
10829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
10839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
1084c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks
1085c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_RAW_IMAGE:
1086e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mRawImageCallback != null) {
10879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
1088e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
10899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
10909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1091c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_COMPRESSED_IMAGE:
1092e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mJpegCallback != null) {
10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
1094e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
10969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
1097c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_PREVIEW_FRAME:
1098ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                PreviewCallback pCb = mPreviewCallback;
1099ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                if (pCb != null) {
11009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    if (mOneShot) {
1101a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Clear the callback variable before the callback
1102a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // in case the app calls setPreviewCallback from
1103a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the callback function
11049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        mPreviewCallback = null;
110594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                    } else if (!mWithBuffer) {
1106a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // We're faking the camera preview mode to prevent
1107a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the app from being flooded with preview frames.
1108a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Set to oneshot mode again.
110994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                        setHasPreviewCallback(true, false);
11109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    }
1111ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                    pCb.onPreviewFrame((byte[])msg.obj, mCamera);
11129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
11139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1115e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_POSTVIEW_FRAME:
1116e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mPostviewCallback != null) {
1117e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                    mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
1118e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
1119e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
1120e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1121c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_FOCUS:
1122f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                AutoFocusCallback cb = null;
1123f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                synchronized (mAutoFocusCallbackLock) {
1124f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb = mAutoFocusCallback;
1125f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                }
1126f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                if (cb != null) {
1127f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    boolean success = msg.arg1 == 0 ? false : true;
1128f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb.onAutoFocus(success, mCamera);
1129e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
1130e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
1131e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1132e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_ZOOM:
11333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                if (mZoomListener != null) {
11343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                    mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
1135e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
11369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1138bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li            case CAMERA_MSG_PREVIEW_METADATA:
11394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                if (mFaceListener != null) {
1140f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li                    mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
11414c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                }
11424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                return;
11434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1144c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_ERROR :
11459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Error " + msg.arg1);
1146e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mErrorCallback != null) {
11479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mErrorCallback.onError(msg.arg1, mCamera);
1148e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
11499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11519d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li            case CAMERA_MSG_FOCUS_MOVE:
11529d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                if (mAutoFocusMoveCallback != null) {
11539d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                    mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
11549d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                }
11559d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                return;
11569d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
11579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            default:
11589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Unknown message type " + msg.what);
11599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static void postEventFromNative(Object camera_ref,
11659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                            int what, int arg1, int arg2, Object obj)
11669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
11679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Camera c = (Camera)((WeakReference)camera_ref).get();
11689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c == null)
11699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
11709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c.mEventHandler != null) {
11729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
11739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            c.mEventHandler.sendMessage(m);
11749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1178bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to notify on completion of camera auto focus.
1179bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
11807478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * <p>Devices that do not support auto-focus will receive a "fake"
11817478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * callback to this interface. If your application needs auto-focus and
1182df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * should not be installed on devices <em>without</em> auto-focus, you must
1183df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * declare that your app uses the
11847478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * {@code android.hardware.camera.autofocus} feature, in the
1185df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1186df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1187bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1188bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(AutoFocusCallback)
1189b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1190b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1192b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface AutoFocusCallback
11949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
11959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
119669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * Called when the camera auto focus completes.  If the camera
119769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * does not support auto-focus and autoFocus is called,
119869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * onAutoFocus will be called immediately with a fake value of
119969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <code>success</code> set to <code>true</code>.
12009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
1201b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * The auto-focus routine does not lock auto-exposure and auto-white
1202b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * balance after it completes.
120383d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         *
12049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param success true if focus was successful, false if otherwise
12059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
120683d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
120783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
12099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onAutoFocus(boolean success, Camera camera);
121053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li    }
12119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1213bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts camera auto-focus and registers a callback function to run when
1214bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the camera is focused.  This method is only valid when preview is active
1215bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * (between {@link #startPreview()} and before {@link #stopPreview()}).
1216bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1217bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callers should check
1218bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1219bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this method should be called. If the camera does not support auto-focus,
1220bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
122136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li     * callback will be called immediately.
1222bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1223da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main     * <p>If your application should not be installed
12247478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * on devices without auto-focus, you must declare that your application
12257478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * uses auto-focus with the
1226df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1227df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1228bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1229068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * <p>If the current flash mode is not
1230068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
1231bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * fired during auto-focus, depending on the driver and camera hardware.<p>
12327478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     *
123353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
1234b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1235b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * do not change during and after autofocus. But auto-focus routine may stop
1236b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * auto-exposure and auto-white balance transiently during focusing.
123783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     *
123853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Stopping preview with {@link #stopPreview()}, or triggering still
123953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * image capture with {@link #takePicture(Camera.ShutterCallback,
124053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
124153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * the focus position. Applications must call cancelAutoFocus to reset the
124253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * focus.</p>
124353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1244108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If autofocus is successful, consider using
1245108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * {@link android.media.MediaActionSound} to properly play back an autofocus
1246108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * success sound to the user.</p>
1247108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param cb the callback to run
1249bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #cancelAutoFocus()
125083d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
125183d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
1252108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
12539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
12549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void autoFocus(AutoFocusCallback cb)
12559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
1256f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1257248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = cb;
1258248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1259f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_autoFocus();
12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_autoFocus();
12629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1264bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Cancels any auto-focus function in progress.
1265bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Whether or not auto-focus is currently in progress,
1266bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this function will return the focus position to the default.
1267244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     * If the camera does not support auto-focus, this is a no-op.
1268bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1269bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(Camera.AutoFocusCallback)
1270244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     */
1271244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    public final void cancelAutoFocus()
1272244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    {
1273f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1274248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = null;
1275248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1276f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_cancelAutoFocus();
1277f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // CAMERA_MSG_FOCUS should be removed here because the following
1278f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // scenario can happen:
1279f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - An application uses the same thread for autoFocus, cancelAutoFocus
1280f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   and looper thread.
1281f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application calls autoFocus.
1282f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1283f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   Before event handler's handleMessage() is invoked, the application
1284f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   calls cancelAutoFocus and autoFocus.
1285f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1286f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   has been completed. But in fact it is not.
1287f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //
1288f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // As documented in the beginning of the file, apps should not use
1289f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // multiple threads to call autoFocus and cancelAutoFocus at the same
1290f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1291f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // message after native_cancelAutoFocus is called.
1292f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
1293244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    }
1294244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    private native final void native_cancelAutoFocus();
1295244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang
1296244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    /**
12979d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Callback interface used to notify on auto focus start and stop.
12989d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
12996574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * <p>This is only supported in continuous autofocus modes -- {@link
13006574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
13016574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
13026574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * autofocus animation based on this.</p>
1303b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1304b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1305b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
13069d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
1307b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
13089d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public interface AutoFocusMoveCallback
13099d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    {
13109d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        /**
13119d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * Called when the camera auto focus starts or stops.
13129d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         *
13139d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * @param start true if focus starts to move, false if focus stops to move
13146574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li         * @param camera the Camera service object
13159d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         */
13169d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        void onAutoFocusMoving(boolean start, Camera camera);
13179d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
13189d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
13199d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
13209d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Sets camera auto-focus move callback.
13219d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
13229d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * @param cb the callback to run
13239d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
13249d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
13259d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = cb;
13269d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
13279d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
13289d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
13299d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private native void enableFocusMoveCallback(int enable);
13309d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
13319d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
1332bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to signal the moment of actual image capture.
1333bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1334bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
1335b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1336b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1337b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
13389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1339b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
13409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ShutterCallback
13419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
13429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1343bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as near as possible to the moment when a photo is captured
1344bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * from the sensor.  This is a good opportunity to play a shutter sound
1345bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * or give other feedback of camera operation.  This may be some time
1346bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * after the photo was triggered, but some time before the actual data
1347bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * is available.
13489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
13499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onShutter();
13509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1353bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to supply image data from a photo capture.
1354bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1355bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
1356b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1357b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1358b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
13599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1360b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
13619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PictureCallback {
13629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1363bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when image data is available after a picture is taken.
1364bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * The format of the data depends on the context of the callback
1365bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * and {@link Camera.Parameters} settings.
13669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
13679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param data   a byte array of the picture data
13689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera the Camera service object
13699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
13709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPictureTaken(byte[] data, Camera camera);
13719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
13729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1374bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Equivalent to takePicture(shutter, raw, null, jpeg).
13759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
1376bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
13779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
13799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            PictureCallback jpeg) {
1380e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        takePicture(shutter, raw, null, jpeg);
1381e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
1382e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void native_takePicture(int msgType);
1383e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1384e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
13859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * Triggers an asynchronous image capture. The camera service will initiate
13869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * a series of callbacks to the application as the image capture progresses.
13879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The shutter callback occurs after the image is captured. This can be used
13889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * to trigger a sound to let the user know that image has been captured. The
13899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * raw callback occurs when the raw image data is available (NOTE: the data
1390e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * will be null if there is no raw image callback buffer available or the
1391e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * raw image callback buffer is not large enough to hold the raw image).
13929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The postview callback occurs when a scaled, fully processed postview
13939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * image is available (NOTE: not all hardware supports this). The jpeg
13949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * callback occurs when the compressed image is available. If the
13959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * application does not need a particular callback, a null can be passed
13969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * instead of a callback method.
1397e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     *
1398bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only valid when preview is active (after
1399bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #startPreview()}).  Preview will be stopped after the image is
1400bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * taken; callers must call {@link #startPreview()} again if they want to
140142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * re-start preview or take more pictures. This should not be called between
140242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()} and
140342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#stop()}.
140440057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1405bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>After calling this method, you must not call {@link #startPreview()}
1406bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * or take another picture until the JPEG callback has returned.
140740057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1408bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param shutter   the callback for image capture moment, or null
1409bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param raw       the callback for raw (uncompressed) image data, or null
1410e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     * @param postview  callback with postview image data, may be null
1411bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param jpeg      the callback for JPEG image data, or null
1412e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
1413e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1414e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            PictureCallback postview, PictureCallback jpeg) {
14159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = shutter;
14169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = raw;
1417e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = postview;
14189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = jpeg;
1419e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1420e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // If callback is not set, do not send me callbacks.
1421e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        int msgType = 0;
1422e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mShutterCallback != null) {
1423e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_SHUTTER;
1424e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1425e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mRawImageCallback != null) {
1426e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_RAW_IMAGE;
1427e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1428e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mPostviewCallback != null) {
1429e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1430e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1431e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mJpegCallback != null) {
1432e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1433e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1434e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1435e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        native_takePicture(msgType);
1436e9c6c9ccfde7a642a4c0554e2d066f3dbbea98ceWu-cheng Li        mFaceDetectionRunning = false;
14379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
14389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1439e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
1440bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Zooms to the requested value smoothly. The driver will notify {@link
14413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
14423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * the time. For example, suppose the current zoom is 0 and startSmoothZoom
1443bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with value 3. The
1444bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1445bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method will be called three times with zoom values 1, 2, and 3.
1446bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1447bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications should not call startSmoothZoom again or change the zoom
1448bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * value before zoom stops. If the supplied zoom value equals to the current
1449bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * zoom value, no zoom callback will be generated. This method is supported
1450bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1451bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * returns true.
145236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *
145336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * @param value zoom value. The valid range is 0 to {@link
145436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *              android.hardware.Camera.Parameters#getMaxZoom}.
14550ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws IllegalArgumentException if the zoom value is invalid.
14560ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
1457bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
145836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
145936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void startSmoothZoom(int value);
146036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
146136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
1462bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops the smooth zoom. Applications should wait for the {@link
14633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} to know when the zoom is actually stopped. This
14643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * method is supported if {@link
14658cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
14660ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     *
14670ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
146836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
146936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void stopSmoothZoom();
147036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
147136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
14722fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * Set the clockwise rotation of preview display in degrees. This affects
14732fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * the preview frames and the picture displayed after snapshot. This method
14742fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * is useful for portrait mode applications. Note that preview display of
1475b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * front-facing cameras is flipped horizontally before the rotation, that
1476b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * is, the image is reflected along the central vertical axis of the camera
1477b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * sensor. So the users can see themselves as looking into a mirror.
1478d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
147969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>This does not affect the order of byte array passed in {@link
14802fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
14812fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * method is not allowed to be called during preview.
1482d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
148369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>If you want to make the camera image show in the same orientation as
148469ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * the display, you can use the following code.
1485b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * <pre>
1486724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * public static void setCameraDisplayOrientation(Activity activity,
1487724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         int cameraId, android.hardware.Camera camera) {
1488724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.CameraInfo info =
1489724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             new android.hardware.Camera.CameraInfo();
1490724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.getCameraInfo(cameraId, info);
1491724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int rotation = activity.getWindowManager().getDefaultDisplay()
1492724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             .getRotation();
1493724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int degrees = 0;
1494724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     switch (rotation) {
1495724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_0: degrees = 0; break;
1496724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_90: degrees = 90; break;
1497724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_180: degrees = 180; break;
1498724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_270: degrees = 270; break;
1499724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     }
1500b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     *
15012fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     int result;
15022fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
15032fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation + degrees) % 360;
15042fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (360 - result) % 360;  // compensate the mirror
15052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     } else {  // back-facing
15062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation - degrees + 360) % 360;
15072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     }
1508724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     camera.setDisplayOrientation(result);
1509724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * }
1510b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * </pre>
1511d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1512d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * <p>Starting from API level 14, this method can be called when preview is
1513d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * active.
1514d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1515d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     * @param degrees the angle that the picture will be rotated clockwise.
1516e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                Valid values are 0, 90, 180, and 270. The starting
1517e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                position is 0 (landscape).
15182fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * @see #setPreviewDisplay(SurfaceHolder)
1519d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     */
1520d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    public native final void setDisplayOrientation(int degrees);
1521d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang
1522d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    /**
1523487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Enable or disable the default shutter sound when taking a picture.</p>
152469fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1525487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>By default, the camera plays the system-defined camera shutter sound
1526487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * when {@link #takePicture} is called. Using this method, the shutter sound
1527487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be disabled. It is strongly recommended that an alternative shutter
1528487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is played in the {@link ShutterCallback} when the system shutter
1529487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is disabled.</p>
153069fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1531487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Note that devices may not always allow disabling the camera shutter
1532487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound. If the shutter sound state cannot be set to the desired value,
1533487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * this method will return false. {@link CameraInfo#canDisableShutterSound}
1534487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be used to determine whether the device will allow the shutter sound
1535487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * to be disabled.</p>
153669fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
153769fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @param enabled whether the camera should play the system shutter sound
153869fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *                when {@link #takePicture takePicture} is called.
1539487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @return {@code true} if the shutter sound state was successfully
1540487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code false} if the shutter sound state could not be
1541487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code true} is also returned if shutter sound playback
1542487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         is already set to the requested state.
154369fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see #takePicture
1544487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @see CameraInfo#canDisableShutterSound
154569fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see ShutterCallback
154669fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     */
15474f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public final boolean enableShutterSound(boolean enabled) {
15484f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        if (!enabled) {
15494f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
15504f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            IAudioService audioService = IAudioService.Stub.asInterface(b);
15514f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            try {
15524f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                if (audioService.isCameraSoundForced()) return false;
15534f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            } catch (RemoteException e) {
15544f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                Log.e(TAG, "Audio service is unavailable for queries");
15554f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
15564f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
15574f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        return _enableShutterSound(enabled);
15584f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
15594f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala
15606653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    /**
15616653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * Disable the shutter sound unconditionally.
15626653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
15636653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * <p>
15646653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * This is only guaranteed to work for legacy cameras
15656653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on
15666653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * a regular camera will force a conditional check in the camera service.
15676653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * </p>
15686653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
15696653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * @return {@code true} if the shutter sound state was successfully
15706653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         changed. {@code false} if the shutter sound state could not be
15716653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         changed. {@code true} is also returned if shutter sound playback
15726653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         is already set to the requested state.
15736653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
15746653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * @hide
15756653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     */
15766653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    public final boolean disableShutterSound() {
15776653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin        return _enableShutterSound(/*enabled*/false);
15786653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    }
15796653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin
15804f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native final boolean _enableShutterSound(boolean enabled);
158169fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala
158269fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala    /**
1583bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for zoom changes during a smooth zoom operation.
1584bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1585bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
1586bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startSmoothZoom(int)
1587b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1588b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1589b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
1590e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
1591b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
15923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public interface OnZoomChangeListener
1593e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
1594e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        /**
1595bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when the zoom value has changed during a smooth zoom.
159636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
159736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param zoomValue the current zoom value. In smooth zoom mode, camera
15983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *                  calls this for every new zoom value.
159936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param stopped whether smooth zoom is stopped. If the value is true,
160036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *                this is the last zoom update for the application.
1601e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         * @param camera  the Camera service object
1602e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         */
16033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        void onZoomChange(int zoomValue, boolean stopped, Camera camera);
1604e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    };
1605e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1606e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
16073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Registers a listener to be notified when the zoom value is updated by the
160836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * camera driver during smooth zoom.
16098cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     *
16103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * @param listener the listener to notify
16118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * @see #startSmoothZoom(int)
1612e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
16133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public final void setZoomChangeListener(OnZoomChangeListener listener)
1614e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
16153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = listener;
1616e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
16179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
16184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
16194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Callback interface for face detected in the preview frame.
16204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1621b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1622b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
16234c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1624b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
16254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public interface FaceDetectionListener
16264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
16274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
16284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Notify the listener of the detected faces in the preview frame.
16294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
163053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @param faces The detected faces in a list
1631464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @param camera  The {@link Camera} service object
16324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1633f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li        void onFaceDetection(Face[] faces, Camera camera);
16344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
16354c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
16364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1637c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Registers a listener to be notified about the faces detected in the
16384c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * preview frame.
16394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
16404c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @param listener the listener to notify
1641c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see #startFaceDetection()
16424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
16434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void setFaceDetectionListener(FaceDetectionListener listener)
16444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
16454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceListener = listener;
16464c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
16474c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
16484c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1649c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Starts the face detection. This should be called after preview is started.
16504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * The camera will notify {@link FaceDetectionListener} of the detected
16514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * faces in the preview frame. The detected faces may be the same as the
16524c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * previous ones. Applications should call {@link #stopFaceDetection} to
16534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * stop the face detection. This method is supported if {@link
1654c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
16554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * If the face detection has started, apps should not call this again.
16564c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
16578c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
16584c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
16598c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * have no effect. The camera uses the detected faces to do auto-white balance,
16608c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * auto exposure, and autofocus.
16618c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
16628c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
16638c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * will stop sending face callbacks. The last face callback indicates the
16648c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * areas used to do autofocus. After focus completes, face detection will
16658c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * resume sending face callbacks. If the apps call {@link
16668c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * #cancelAutoFocus()}, the face callbacks will also resume.</p>
16678c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
16688c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
16698c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
16708c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * preview with {@link #startPreview()}, the apps should call this method
16718c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * again to resume face detection.</p>
16724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1673c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @throws IllegalArgumentException if the face detection is unsupported.
16744c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @throws RuntimeException if the method fails or the face detection is
16754c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *         already running.
16764c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see FaceDetectionListener
16774c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see #stopFaceDetection()
1678c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see Parameters#getMaxNumDetectedFaces()
16794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1680c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    public final void startFaceDetection() {
16814c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        if (mFaceDetectionRunning) {
16824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li            throw new RuntimeException("Face detection is already running");
16834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
1684c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        _startFaceDetection(CAMERA_FACE_DETECTION_HW);
16854c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = true;
16864c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
16874c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
16884c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1689c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Stops the face detection.
16904c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1691464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see #startFaceDetection()
16924c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
16934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopFaceDetection() {
16944c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopFaceDetection();
16954c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
16964c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
16974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
16984c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _startFaceDetection(int type);
16994c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopFaceDetection();
17004c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
17014c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1702464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * Information about a face identified through camera face detection.
170353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1704464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1705464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * list of face objects for use in focusing and metering.</p>
17064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1707464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see FaceDetectionListener
1708b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1709b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
17104c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1711b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
1712f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li    public static class Face {
1713c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        /**
1714c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * Create an empty face.
1715c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         */
1716bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Face() {
1717bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        }
1718bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li
17194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
17204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Bounds of the face. (-1000, -1000) represents the top-left of the
17214c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * camera field of view, and (1000, 1000) represents the bottom-right of
1722c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * the field of view. For example, suppose the size of the viewfinder UI
1723c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
17248c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
17258c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * guaranteed left < right and top < bottom. The coordinates can be
17268c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * smaller than -1000 or bigger than 1000. But at least one vertex will
17278c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * be within (-1000, -1000) and (1000, 1000).
1728f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         *
1729f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * <p>The direction is relative to the sensor orientation, that is, what
1730f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * the sensor sees. The direction is not affected by the rotation or
17318c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
17328c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * rectangle does not provide any information about face orientation.</p>
17338c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         *
17348c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <p>Here is the matrix to convert driver coordinates to View coordinates
17358c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * in pixels.</p>
17368c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <pre>
17378c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * Matrix matrix = new Matrix();
17388c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
17398c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Need mirror for front camera.
17408c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
17418c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.setScale(mirror ? -1 : 1, 1);
17428c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // This is the value for android.hardware.Camera.setDisplayOrientation.
17438c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postRotate(displayOrientation);
17448c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
17458c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // UI coordinates range from (0, 0) to (width, height).
17468c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
17478c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
17488c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * </pre>
17494c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1750464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
17514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1752bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Rect rect;
17534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
17544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
17558df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>The confidence level for the detection of the face. The range is 1 to
17568df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * 100. 100 is the highest confidence.</p>
17578df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         *
17588df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>Depending on the device, even very low-confidence faces may be
17598df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * listed, so applications should filter out faces with low confidence,
17608df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * depending on the use case. For a typical point-and-shoot camera
17618df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * application that wishes to display rectangles around detected faces,
17628df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * filtering out faces with confidence less than 50 is recommended.</p>
17634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1764464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
17654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1766bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public int score;
1767d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1768d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1769d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * An unique id per face while the face is visible to the tracker. If
1770d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the face leaves the field-of-view and comes back, it will get a new
1771d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * id. This is an optional field, may not be supported on all devices.
1772d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * If not supported, id will always be set to -1. The optional fields
1773d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are supported as a set. Either they are all valid, or none of them
1774d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are.
1775d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1776d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public int id = -1;
1777d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1778d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1779d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the left eye. The coordinates are in
1780d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1781d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1782d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1783d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1784d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1785d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point leftEye = null;
1786d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1787d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1788d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the right eye. The coordinates are
1789d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * in the same space as the ones for {@link #rect}.This is an optional
1790d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1791d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1792d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1793d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1794d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point rightEye = null;
1795d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1796d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1797d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the mouth.  The coordinates are in
1798d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1799d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1800d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1801d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1802d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1803d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point mouth = null;
18044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
18054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1806bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1807bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unspecified camera error.
1808bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1809bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
18109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_UNKNOWN = 1;
1811bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1812bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1813e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     * Camera was disconnected due to use by higher priority user.
1814e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     * @see Camera.ErrorCallback
1815e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     */
1816e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk    public static final int CAMERA_ERROR_EVICTED = 2;
1817e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk
1818e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk    /**
1819bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Media server died. In this case, the application must release the
1820bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera object and instantiate a new one.
1821bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1822bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
18239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_SERVER_DIED = 100;
18249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1826bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for camera error notification.
1827bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1828bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setErrorCallback(ErrorCallback)
1829b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1830b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1831b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
18329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1833b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
18349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ErrorCallback
18359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
18369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
18379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Callback for camera errors.
18389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param error   error code:
18399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <ul>
18409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_UNKNOWN}
18419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_SERVER_DIED}
18429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * </ul>
18439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
18449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
18459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onError(int error, Camera camera);
18469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
18479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
18499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Registers a callback to be invoked when an error occurs.
1850bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb The callback to run
18519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
18529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setErrorCallback(ErrorCallback cb)
18539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
18549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mErrorCallback = cb;
18559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
18569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_setParameters(String params);
18589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final String native_getParameters();
18599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1861bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Changes the settings for this Camera service.
18629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
18639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param params the Parameters to use for this Camera service
186499a3f3e4e06b4370101ca97cc11dbe81d772fefaWu-cheng Li     * @throws RuntimeException if any parameter is invalid or not supported.
1865bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #getParameters()
18669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
18679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setParameters(Parameters params) {
18687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // If using preview allocations, don't allow preview size changes
18697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (mUsingPreviewAllocation) {
18707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size newPreviewSize = params.getPreviewSize();
18717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size currentPreviewSize = getParameters().getPreviewSize();
18727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            if (newPreviewSize.width != currentPreviewSize.width ||
18737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                    newPreviewSize.height != currentPreviewSize.height) {
18747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                throw new IllegalStateException("Cannot change preview size" +
18757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        " while a preview allocation is configured.");
18767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            }
18777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
18787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
18799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_setParameters(params.flatten());
18809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
18819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1883bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Returns the current settings for this Camera service.
1884bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * If modifications are made to the returned Parameters, they must be passed
1885bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to {@link #setParameters(Camera.Parameters)} to take effect.
1886bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1887bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setParameters(Camera.Parameters)
18889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
18899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public Parameters getParameters() {
18909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Parameters p = new Parameters();
18919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String s = native_getParameters();
18929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        p.unflatten(s);
18939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return p;
18949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
18959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
18969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
18971c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * Returns an empty {@link Parameters} for testing purpose.
18981c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
1899f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * @return a Parameter object.
19001c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
19011c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * @hide
19021c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
19031c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    public static Parameters getEmptyParameters() {
19041c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        Camera camera = new Camera();
19051c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        return camera.new Parameters();
19061c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
19071c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
19081c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
1909df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * Returns a copied {@link Parameters}; for shim use only.
1910df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     *
1911df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @param parameters a non-{@code null} parameters
1912df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @return a Parameter object, with all the parameters copied from {@code parameters}.
1913df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     *
1914df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @throws NullPointerException if {@code parameters} was {@code null}
1915df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @hide
1916df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     */
1917df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    public static Parameters getParametersCopy(Camera.Parameters parameters) {
1918df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        if (parameters == null) {
1919df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            throw new NullPointerException("parameters must not be null");
1920df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
1921df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
1922df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        Camera camera = parameters.getOuter();
1923df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        Parameters p = camera.new Parameters();
1924df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        p.copyFrom(parameters);
1925df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
1926df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        return p;
1927df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    }
1928df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
1929df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    /**
1930bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Image size (width and height dimensions).
1931b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1932b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
19339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1934b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
19359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Size {
19369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
19379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the dimensions for pictures.
19389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
19399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param w the photo width (pixels)
19409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param h the photo height (pixels)
19419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
19429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size(int w, int h) {
19439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            width = w;
19449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            height = h;
19459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
19464c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
19474c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Compares {@code obj} to this size.
19484c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
19494c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @param obj the object to compare this size with.
19504c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @return {@code true} if the width and height of {@code obj} is the
19514c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         same as those of this size. {@code false} otherwise.
19524c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
19534c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
19544c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public boolean equals(Object obj) {
19554c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            if (!(obj instanceof Size)) {
19564c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li                return false;
19574c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            }
19584c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            Size s = (Size) obj;
19594c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width == s.width && height == s.height;
19604c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
19614c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
19624c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public int hashCode() {
19634c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width * 32713 + height;
19644c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
19659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** width of the picture */
19669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int width;
19679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** height of the picture */
19689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int height;
19699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
19709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
197232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The Area class is used for choosing specific metering and focus areas for
197332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the camera to use when calculating auto-exposure, auto-white balance, and
197432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * auto-focus.</p>
197532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
197632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>To find out how many simultaneous areas a given camera supports, use
197732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumMeteringAreas()} and
197832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
197932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * selection is unsupported, these methods will return 0.</p>
198032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
198132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Each Area consists of a rectangle specifying its bounds, and a weight
198232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * that determines its importance. The bounds are relative to the camera's
198332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * current field of view. The coordinates are mapped so that (-1000, -1000)
198432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * is always the top-left corner of the current field of view, and (1000,
198532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * 1000) is always the bottom-right corner of the current field of
198632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * view. Setting Areas with bounds outside that range is not allowed. Areas
198732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * with zero or negative width or height are not allowed.</p>
198832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
198932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The weight must range from 1 to 1000, and represents a weight for
199032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * every pixel in the area. This means that a large metering area with
199132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the same weight as a smaller area will have more effect in the
199232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * metering result.  Metering areas can overlap and the driver
199332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * will add the weights in the overlap region.</p>
1994bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     *
1995bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setFocusAreas(List)
1996bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getFocusAreas()
1997bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumFocusAreas()
1998bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setMeteringAreas(List)
1999bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMeteringAreas()
2000bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumMeteringAreas()
2001b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
2002b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2003b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
200430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li     */
2005b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
200630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    public static class Area {
200730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
200830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Create an area with specified rectangle and weight.
200930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
201032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param rect the bounds of the area.
201132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param weight the weight of the area.
201230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
201330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Area(Rect rect, int weight) {
201430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.rect = rect;
201530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.weight = weight;
201630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
201730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
201830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Compares {@code obj} to this area.
201930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
202030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @param obj the object to compare this area with.
202130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return {@code true} if the rectangle and weight of {@code obj} is
202230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *         the same as those of this area. {@code false} otherwise.
202330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
202430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        @Override
202530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public boolean equals(Object obj) {
202630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (!(obj instanceof Area)) {
202730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return false;
202830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
202930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            Area a = (Area) obj;
203030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (rect == null) {
203130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (a.rect != null) return false;
203230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } else {
203330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (!rect.equals(a.rect)) return false;
203430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
203530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return weight == a.weight;
203630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
203730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
2038bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
203932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Bounds of the area. (-1000, -1000) represents the top-left of the
204032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * camera field of view, and (1000, 1000) represents the bottom-right of
204132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the field of view. Setting bounds outside that range is not
204232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed. Bounds with zero or negative width or height are not
204332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed.
2044bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
2045bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
2046bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
2047bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
204830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Rect rect;
204930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
2050bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
205132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Weight of the area. The weight must range from 1 to 1000, and
205232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * represents a weight for every pixel in the area. This means that a
205332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * large metering area with the same weight as a smaller area will have
205432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * more effect in the metering result.  Metering areas can overlap and
205532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the driver will add the weights in the overlap region.
2056bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
2057bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
2058bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
2059bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
206030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int weight;
2061bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li    }
206230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
206330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    /**
2064bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera service settings.
20659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
20669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>To make camera parameters take effect, applications have to call
2067bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera#setParameters(Camera.Parameters)}. For example, after
2068bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
2069bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * actually changed until {@link Camera#setParameters(Camera.Parameters)}
2070bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with the changed parameters object.
20719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
20729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>Different devices may have different camera capabilities, such as
20739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * picture size or flash modes. The application should query the camera
20749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * capabilities before setting parameters. For example, the application
2075bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * should call {@link Camera.Parameters#getSupportedColorEffects()} before
2076bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling {@link Camera.Parameters#setColorEffect(String)}. If the
2077bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera does not support color effects,
2078bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
2079b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
2080b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2081b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
20829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2083b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
20849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Parameters {
20859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter keys to communicate with the camera driver.
20869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_SIZE = "preview-size";
20879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FORMAT = "preview-format";
20889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
2089454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
20909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_SIZE = "picture-size";
20919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_FORMAT = "picture-format";
20924c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
20939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
20949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
20959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
20969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_QUALITY = "jpeg-quality";
20979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ROTATION = "rotation";
20989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LATITUDE = "gps-latitude";
20999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LONGITUDE = "gps-longitude";
21009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_ALTITUDE = "gps-altitude";
21019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
2102055c986ab841f8f758398841730f1e90313b132aRay Chen        private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
21039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_WHITE_BALANCE = "whitebalance";
21049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_EFFECT = "effect";
21059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ANTIBANDING = "antibanding";
21069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_SCENE_MODE = "scene-mode";
21079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_FLASH_MODE = "flash-mode";
210836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        private static final String KEY_FOCUS_MODE = "focus-mode";
210930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_FOCUS_AREAS = "focus-areas";
211030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
21116c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_FOCAL_LENGTH = "focal-length";
21126c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
21136c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
2114ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
211524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
211624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
211724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
21183773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
21193773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
2120d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
2121d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
2122e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_METERING_AREAS = "metering-areas";
2123e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
21248cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM = "zoom";
21258cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_MAX_ZOOM = "max-zoom";
21268cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
21278cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
21288cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
2129e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        private static final String KEY_FOCUS_DISTANCES = "focus-distances";
2130dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_VIDEO_SIZE = "video-size";
2131dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
2132dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong                                            "preferred-preview-size-for-video";
21334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
21344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
213525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        private static final String KEY_RECORDING_HINT = "recording-hint";
213698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
2137037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
2138037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
2139e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
21409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter key suffix for supported values.
21419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String SUPPORTED_VALUES_SUFFIX = "-values";
21429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21438cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String TRUE = "true";
21443773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String FALSE = "false";
21458cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li
21469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for white balance settings.
21479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_AUTO = "auto";
21489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
21499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
21509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
21519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
21529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
21539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_TWILIGHT = "twilight";
21549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_SHADE = "shade";
21559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for color effect settings.
21579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NONE = "none";
21589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_MONO = "mono";
21599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NEGATIVE = "negative";
21609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SOLARIZE = "solarize";
21619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SEPIA = "sepia";
21629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_POSTERIZE = "posterize";
21639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_WHITEBOARD = "whiteboard";
21649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_BLACKBOARD = "blackboard";
21659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_AQUA = "aqua";
21669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for antibanding settings.
21689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_AUTO = "auto";
21699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_50HZ = "50hz";
21709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_60HZ = "60hz";
21719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_OFF = "off";
21729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for flash mode settings.
21749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
21759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will not be fired.
21769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
21779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_OFF = "off";
217836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
21799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2180068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will be fired automatically when required. The flash may be fired
2181068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * during preview, auto-focus, or snapshot depending on the driver.
21829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
21839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_AUTO = "auto";
218436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
21859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2186068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will always be fired during snapshot. The flash may also be
2187068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * fired during preview or auto-focus depending on the driver.
21889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
21899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_ON = "on";
219036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
21919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
21929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will be fired in red-eye reduction mode.
21939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
21949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_RED_EYE = "red-eye";
219536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
219636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
2197068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Constant emission of light during preview, auto-focus and snapshot.
2198068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * This can also be used for video recording.
219936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
2200068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li        public static final String FLASH_MODE_TORCH = "torch";
22019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
220200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
220300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Scene mode is off.
220400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_AUTO = "auto";
220600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
220700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
220800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
220900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_SPORTS}.
221000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_ACTION = "action";
221200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
221300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
221400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures.
221500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PORTRAIT = "portrait";
221700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
221800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
221900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on distant objects.
222000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_LANDSCAPE = "landscape";
222200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
222300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
222400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos at night.
222500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT = "night";
222700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
222800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
222900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures at night.
223000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
223200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
223300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
223400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos in a theater. Flash light is off.
223500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_THEATRE = "theatre";
223700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
223800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
223900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the beach.
224000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_BEACH = "beach";
224200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
224300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
224400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the snow.
224500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SNOW = "snow";
224700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
224800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
224900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take sunset photos.
225000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SUNSET = "sunset";
225200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
225300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
225400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Avoid blurry pictures (for example, due to hand shake).
225500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
225700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
225800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
225900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * For shooting firework displays.
226000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_FIREWORKS = "fireworks";
226200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
226300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
226400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
226500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_ACTION}.
226600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SPORTS = "sports";
226800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
226900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
227000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take indoor low-light shot.
227100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PARTY = "party";
227300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
227400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
227500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Capture the naturally warm color of scenes lit by candles.
227600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
22779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
22789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
2279c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2280c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Applications are looking for a barcode. Camera driver will be
2281c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * optimized for barcode reading.
2282c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2283c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String SCENE_MODE_BARCODE = "barcode";
2284c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
228536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
2286da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * Capture a scene using high dynamic range imaging techniques. The
2287da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * camera will return an image that has an extended dynamic range
2288da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * compared to a regular capture. Capturing such an image may take
2289da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * longer than a regular capture.
2290da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         */
2291da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        public static final String SCENE_MODE_HDR = "hdr";
2292da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala
2293da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        /**
2294f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Auto-focus mode. Applications should call {@link
2295f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
229636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
229736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_AUTO = "auto";
229836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
229936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
230036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is set at infinity. Applications should not call
230136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} in this mode.
230236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
230336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_INFINITY = "infinity";
2304f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li
2305f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li        /**
2306f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Macro (close-up) focus mode. Applications should call
2307f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2308f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * mode.
2309f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         */
231036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_MACRO = "macro";
231136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
231236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
231336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is fixed. The camera is always in this mode if the focus is not
231436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * adjustable. If the camera has auto-focus, this mode can fix the
231536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * focus, which is usually at hyperfocal distance. Applications should
231636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
231736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
231836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_FIXED = "fixed";
231936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
2320c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2321c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Extended depth of field (EDOF). Focusing is done digitally and
2322c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * continuously. Applications should not call {@link
2323c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode.
2324c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2325c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String FOCUS_MODE_EDOF = "edof";
2326c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
2327699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li        /**
2328d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * Continuous auto focus mode intended for video recording. The camera
2329b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. This is the best choice for video
2330b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * recording because the focus changes smoothly . Applications still can
2331b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * call {@link #takePicture(Camera.ShutterCallback,
2332b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2333b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * subject may not be in focus. Auto focus starts when the parameter is
233453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * set.
233553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
233653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * <p>Since API level 14, applications can call {@link
233753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
233853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * immediately return with a boolean that indicates whether the focus is
233953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * sharp or not. The focus position is locked after autoFocus call. If
234053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * applications want to resume the continuous focus, cancelAutoFocus
234153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * must be called. Restarting the preview will not resume the continuous
234253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * autofocus. To stop continuous focus, applications should change the
234353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * focus mode to other modes.
234453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
234553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_PICTURE
2346d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         */
2347d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
2348699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li
2349b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        /**
2350b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Continuous auto focus mode intended for taking pictures. The camera
2351b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. The speed of focus change is more
2352b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
235353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * starts when the parameter is set.
235453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
23550f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
23560f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * this mode. If the autofocus is in the middle of scanning, the focus
23570f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * callback will return when it completes. If the autofocus is not
23580f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * scanning, the focus callback will immediately return with a boolean
23590f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * that indicates whether the focus is sharp or not. The apps can then
23600f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * decide if they want to take a picture immediately or to change the
23610f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * focus mode to auto, and run a full autofocus cycle. The focus
23620f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * position is locked after autoFocus call. If applications want to
23630f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * resume the continuous focus, cancelAutoFocus must be called.
23640f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * Restarting the preview will not resume the continuous autofocus. To
23650f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * stop continuous focus, applications should change the focus mode to
23660f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * other modes.
2367b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         *
2368b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
2369b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         */
2370b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2371b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li
2372e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Indices for focus distance array.
2373e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2374e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of near focus distance for use with
2375e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2376e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2377e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2378e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2379e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2380e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of optimal focus distance for use with
2381e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2382e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2383e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2384e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2385e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2386e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of far focus distance for use with
2387e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2388e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2389e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2390e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2391ca099614841bc619f217dfa088da630a7eb1ab65Wu-cheng Li        /**
2392454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of minimum preview fps for use with {@link
2393454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2394454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2395454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2396454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MIN_INDEX = 0;
2397454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2398454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2399454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of maximum preview fps for use with {@link
2400454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2401454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2402454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2403454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MAX_INDEX = 1;
2404454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
24059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Formats for setPreviewFormat and setPictureFormat.
24069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
24079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
2408eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang        private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
240910a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
24109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_RGB565 = "rgb565";
24119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_JPEG = "jpeg";
241270fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li        private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
24139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24147d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        /**
24157d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * Order matters: Keys that are {@link #set(String, String) set} later
24167d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * will take precedence over keys that are set earlier (if the two keys
24177d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * conflict with each other).
24187d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         *
24197d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it
24207d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later
24217d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * is the one that will take precedence.
24227d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * </p>
24237d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         */
24247d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        private final LinkedHashMap<String, String> mMap;
24259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Parameters() {
24277d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64);
24289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2431df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * Overwrite existing parameters with a copy of the ones from {@code other}.
2432df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         *
2433df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * <b>For use by the legacy shim only.</b>
2434df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         *
2435df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * @hide
2436df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         */
2437df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        public void copyFrom(Parameters other) {
2438df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            if (other == null) {
2439df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin                throw new NullPointerException("other must not be null");
2440df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            }
2441df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2442df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            mMap.putAll(other.mMap);
2443df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
2444df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2445df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        private Camera getOuter() {
2446df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            return Camera.this;
2447df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
2448df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2449d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk
2450d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        /**
2451d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         * Value equality check.
2452d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         *
2453d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         * @hide
2454d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         */
2455d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        public boolean same(Parameters other) {
2456d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            if (this == other) {
2457d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk                return true;
2458d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            }
2459d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            return other != null && Parameters.this.mMap.equals(other.mMap);
2460d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        }
2461d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk
2462df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        /**
24639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Writes the current Parameters to the log.
24649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @hide
24659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @deprecated
24669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
2467a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        @Deprecated
24689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void dump() {
24699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Log.e(TAG, "dump: size=" + mMap.size());
24709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
24719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
24729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
24739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
24769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Creates a single string with all the parameters set in
24779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
24789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #unflatten(String)} method does the reverse.</p>
24799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return a String with all values from this Parameters object, in
24819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *         semi-colon delimited key-value pairs
24829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String flatten() {
24840a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            StringBuilder flattened = new StringBuilder(128);
24859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
24869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(k);
24879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append("=");
24889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(mMap.get(k));
24899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(";");
24909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
24919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            // chop off the extra semicolon at the end
24929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            flattened.deleteCharAt(flattened.length()-1);
24939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return flattened.toString();
24949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
24979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Takes a flattened string of parameters and adds each one to
24989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
24999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #flatten()} method does the reverse.</p>
25009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param flattened a String of parameters (key-value paired) that
25029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *                  are semi-colon delimited
25039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
25049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void unflatten(String flattened) {
25059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.clear();
25069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25070a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
25080a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(flattened);
25090a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String kv : splitter) {
25109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int pos = kv.indexOf('=');
25119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (pos == -1) {
25129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    continue;
25139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
25149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String k = kv.substring(0, pos);
25159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String v = kv.substring(pos + 1);
25169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                mMap.put(k, v);
25179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
25189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
25199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
25209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void remove(String key) {
25219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.remove(key);
25229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
25239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
25249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
25259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets a String parameter.
25269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
25289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the String value of the parameter
25299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
25309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, String value) {
2531cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2532cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
25339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
25349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
2535cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2536cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
25379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
25389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
25399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
25407d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            put(key, value);
25419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
25429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
25439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
25449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets an integer parameter.
25459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
25479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the int value of the parameter
25489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
25499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, int value) {
25507d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            put(key, Integer.toString(value));
25517d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        }
25527d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin
25537d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        private void put(String key, String value) {
25547d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            /*
25557d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * Remove the key if it already exists.
25567d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             *
25577d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * This way setting a new value for an already existing key will always move
25587d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * that key to be ordered the latest in the map.
25597d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             */
25607d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap.remove(key);
25617d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap.put(key, value);
25629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
25639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2564e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private void set(String key, List<Area> areas) {
2565f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (areas == null) {
2566f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, "(0,0,0,0,0)");
2567f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            } else {
2568f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                StringBuilder buffer = new StringBuilder();
2569f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                for (int i = 0; i < areas.size(); i++) {
2570f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Area area = areas.get(i);
2571f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Rect rect = area.rect;
2572f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append('(');
2573f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.left);
2574f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2575f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.top);
2576f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2577f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.right);
2578f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2579f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.bottom);
2580f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2581f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(area.weight);
2582f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(')');
2583f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    if (i != areas.size() - 1) buffer.append(',');
2584f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
2585f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, buffer.toString());
2586e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            }
2587e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
2588e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
25899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
25909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of a String parameter.
25919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
25929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
25939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the String value of the parameter
25949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
25959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String get(String key) {
25969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mMap.get(key);
25979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
25989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
25999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of an integer parameter.
26019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
26039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the int value of the parameter
26049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getInt(String key) {
26069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return Integer.parseInt(mMap.get(key));
26079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
261026274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * Sets the dimensions for preview pictures. If the preview has already
261126274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * started, applications should stop the preview first before changing
261226274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * preview size.
26139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2614c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * The sides of width and height are based on camera orientation. That
2615c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * is, the preview size is the size before it is rotated by display
2616c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation. So applications need to consider the display orientation
2617c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * while setting preview size. For example, suppose the camera supports
2618c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2619c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * preview ratio. If the display orientation is set to 0 or 180, preview
2620c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * size should be set to 480x320. If the display orientation is set to
2621c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * 90 or 270, preview size should be set to 320x480. The display
2622c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation should also be considered while setting picture size and
2623c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * thumbnail size.
2624c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
26259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the pictures, in pixels
26269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the pictures, in pixels
2627c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setDisplayOrientation(int)
2628c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
2629c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPictureSize(int, int)
2630c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setJpegThumbnailSize(int, int)
26319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewSize(int width, int height) {
26339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
26349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_SIZE, v);
26359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimensions setting for preview pictures.
26399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2640dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a Size object with the width and height setting
26419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for the preview picture
26429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPreviewSize() {
26449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PREVIEW_SIZE);
26459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
26469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview sizes.
26509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
26529c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li         *         with at least one element.
26539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPreviewSizes() {
26559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
26569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
26579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
266032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the supported video frame sizes that can be used by
266132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * MediaRecorder.</p>
2662dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
266332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>If the returned list is not null, the returned list will contain at
2664dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * least one Size and one of the sizes in the returned list must be
2665dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * passed to MediaRecorder.setVideoSize() for camcorder application if
2666dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * camera is used as the video source. In this case, the size of the
2667dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview can be different from the resolution of the recorded video
266832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * during video recording.</p>
2669dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2670dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a list of Size object if camera has separate preview and
2671dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video output; otherwise, null is returned.
2672dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getPreferredPreviewSizeForVideo()
2673dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2674dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public List<Size> getSupportedVideoSizes() {
2675dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2676dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return splitSize(str);
2677dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2678dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2679dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
2680dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * Returns the preferred or recommended preview size (width and height)
2681dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * in pixels for video recording. Camcorder applications should
2682dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * set the preview size to a value that is not larger than the
2683dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preferred preview size. In other words, the product of the width
2684dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * and height of the preview size should not be larger than that of
2685dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * the preferred preview size. In addition, we recommend to choose a
2686dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview size that has the same aspect ratio as the resolution of
2687dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * video to be recorded.
2688dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2689dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return the preferred preview size (width and height) in pixels for
2690dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video recording if getSupportedVideoSizes() does not return
2691dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         null; otherwise, null is returned.
2692dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getSupportedVideoSizes()
2693dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2694dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public Size getPreferredPreviewSizeForVideo() {
2695dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2696dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return strToSize(pair);
2697dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2698dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2699dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
270032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
27014c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * applications set both width and height to 0, EXIF will not contain
270232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * thumbnail.</p>
27039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
270432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
270532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2706c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
27079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the thumbnail, in pixels
27089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the thumbnail, in pixels
2709c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
27109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
27119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailSize(int width, int height) {
27129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
27139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
27149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
27159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
27169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
27179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the dimensions for EXIF thumbnail in Jpeg picture.
27189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
27199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting for the EXIF
27209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         thumbnails
27219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public Size getJpegThumbnailSize() {
27239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
27249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                            getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
27259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27284c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Gets the supported jpeg thumbnail sizes.
27294c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
27303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
27314c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         with at least two elements. Size 0,0 (no thumbnail) is always
27324c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         supported.
27334c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
27344c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public List<Size> getSupportedJpegThumbnailSizes() {
27354c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
27364c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return splitSize(str);
27374c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
27384c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li
27394c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
27409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the quality of the EXIF thumbnail in Jpeg picture.
27419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
27429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
27439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
27449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailQuality(int quality) {
27469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
27479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
27519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
27529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG quality setting of the EXIF thumbnail.
27539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegThumbnailQuality() {
27559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
27569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets Jpeg quality of captured picture.
27609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
27619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of captured picture. The range is 1
27629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
27639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
27649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegQuality(int quality) {
27659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_QUALITY, quality);
27669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
27679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
27689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
27699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the JPEG picture.
27709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG picture quality setting.
27729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegQuality() {
27749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_QUALITY);
27759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2778a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Sets the rate at which preview frames are received. This is the
2779a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * target frame rate. The actual frame rate depends on the driver.
27809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param fps the frame rate (frames per second)
27825f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
27839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27845f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
27859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFrameRate(int fps) {
27869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FRAME_RATE, fps);
27879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2790a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Returns the setting for the rate at which preview frames are
2791a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * received. This is the target frame rate. The actual frame rate
2792a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * depends on the driver.
27939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the frame rate setting (frames per second)
27955f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
27969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27975f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
27989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFrameRate() {
27999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_PREVIEW_FRAME_RATE);
28009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview frame rates.
28049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview frame rates. null if preview
28063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         frame rate setting is not supported.
28075f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
28089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28095f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
28109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFrameRates() {
28119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
28129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitInt(str);
28139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
28149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
28159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
28164a68e3c26dd2512c319071dc20074baa6e7d171fHai Guo         * Sets the minimum and maximum preview fps. This controls the rate of
28171620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li         * preview frames received in {@link PreviewCallback}. The minimum and
2818454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum preview fps must be one of the elements from {@link
2819454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange}.
2820454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2821454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param min the minimum preview fps (scaled by 1000).
2822454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param max the maximum preview fps (scaled by 1000).
2823454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @throws RuntimeException if fps range is invalid.
2824454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2825454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2826454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2827454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void setPreviewFpsRange(int min, int max) {
2828454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2829454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2830454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2831454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2832454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Returns the current minimum and maximum preview fps. The values are
2833454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2834454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2835454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return range the minimum and maximum preview fps (scaled by 1000).
2836454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2837454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2838454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2839454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2840454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void getPreviewFpsRange(int[] range) {
2841454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (range == null || range.length != 2) {
2842454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                throw new IllegalArgumentException(
28435f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li                        "range must be an array with two elements.");
2844454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
2845454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2846454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2847454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2848454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2849454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Gets the supported preview fps (frame-per-second) ranges. Each range
2850454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * contains a minimum fps and maximum fps. If minimum fps equals to
2851454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum fps, the camera outputs frames in fixed frame rate. If not,
2852454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * the camera outputs frames in auto frame rate. The actual frame rate
2853454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * fluctuates between the minimum and the maximum. The values are
2854454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * multiplied by 1000 and represented in integers. For example, if frame
2855454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * rate is 26.623 frames per second, the value is 26623.
2856454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2857454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return a list of supported preview fps ranges. This method returns a
2858454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         list with at least one element. Every element is an int array
2859454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         of two values - minimum fps and maximum fps. The list is
2860454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         sorted from small to large (first by maximum fps and then
2861454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         minimum fps).
2862454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2863454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2864454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2865454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public List<int[]> getSupportedPreviewFpsRange() {
2866454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2867454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return splitRange(str);
2868454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2869454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2870454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
28717478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         * Sets the image format for preview pictures.
2872da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         * <p>If this is never called, the default format will be
2873a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * {@link android.graphics.ImageFormat#NV21}, which
2874df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         * uses the NV21 encoding format.</p>
28757478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
2876951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
2877951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the available preview formats.
2878951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2879951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>It is strongly recommended that either
2880951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#NV21} or
2881951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12} is used, since
2882951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * they are supported by all camera devices.</p>
2883951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2884951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>For YV12, the image buffer that is received is not necessarily
2885951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * tightly packed, as there may be padding at the end of each row of
2886951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * pixel data, as described in
2887951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
2888951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * it can be assumed that the stride of the Y and UV data is the
2889951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * smallest possible that meets the alignment requirements. That is, if
2890951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the preview size is <var>width x height</var>, then the following
2891951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * equations describe the buffer index for the beginning of row
2892951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <var>y</var> for the Y plane and row <var>c</var> for the U and V
2893951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * planes:
2894951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2895951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@code
2896951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <pre>
2897951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yStride   = (int) ceil(width / 16.0) * 16;
2898951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvStride  = (int) ceil( (yStride / 2) / 16.0) * 16;
2899951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * ySize     = yStride * height;
2900951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvSize    = uvStride * height / 2;
2901951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yRowIndex = yStride * y;
2902951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uRowIndex = ySize + uvSize + uvStride * c;
2903951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * vRowIndex = ySize + uvStride * c;
2904951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * size      = ySize + uvSize * 2;</pre>
2905951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * }
2906951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2907951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @param pixel_format the desired preview picture format, defined by
2908951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   one of the {@link android.graphics.ImageFormat} constants.  (E.g.,
2909951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.NV21</var> (default), or
2910951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.YV12</var>)
2911951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2912a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
2913951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
29149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFormat(int pixel_format) {
29169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
29179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
29189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
29199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
29209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
29219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FORMAT, s);
29239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29263f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * Returns the image format for preview frames got from
29279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * {@link PreviewCallback}.
29287478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
29293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the preview format.
29303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
2931951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
29329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFormat() {
29349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
29359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2938f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2939f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported. {@link android.graphics.ImageFormat#YV12}
2940f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported since API level 12.
29419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview formats. This method will always
29433f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
29443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
2945951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
29469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFormats() {
29489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
2949eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            ArrayList<Integer> formats = new ArrayList<Integer>();
2950eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            for (String s : split(str)) {
2951eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                int f = pixelFormatForCameraFormat(s);
2952a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
2953eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                formats.add(f);
2954eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            }
2955eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            return formats;
29569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
295932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for pictures.</p>
29609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
296132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
296232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2963c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
29649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width for pictures, in pixels
29659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height for pictures, in pixels
2966c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
2967c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
29689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureSize(int width, int height) {
29709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
29719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_SIZE, v);
29729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimension setting for pictures.
29769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting
29789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for pictures
29799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPictureSize() {
29819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PICTURE_SIZE);
29829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
29839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture sizes.
29879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported picture sizes. This method will always
29893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
29909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPictureSizes() {
29929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
29939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
29949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the image format for pictures.
29989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param pixel_format the desired picture format
3000a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                     (<var>ImageFormat.NV21</var>,
3001a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.RGB_565</var>, or
3002a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.JPEG</var>)
3003a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
30049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
30059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureFormat(int pixel_format) {
30069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
30079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
30089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
30099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
30109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
30119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_FORMAT, s);
30139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
30149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
30169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the image format for pictures.
30179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the picture format
30193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
30209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
30219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPictureFormat() {
30229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
30239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture formats.
30279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return supported picture formats. This method will always return a
30293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         list with at least one element.
30303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
30319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPictureFormats() {
30339c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
30349c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            ArrayList<Integer> formats = new ArrayList<Integer>();
30359c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            for (String s : split(str)) {
30369c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                int f = pixelFormatForCameraFormat(s);
3037a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
30389c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                formats.add(f);
30399c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            }
30409c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            return formats;
30419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
30429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private String cameraFormatForPixelFormat(int pixel_format) {
30449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(pixel_format) {
3045a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV16:      return PIXEL_FORMAT_YUV422SP;
3046a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV21:      return PIXEL_FORMAT_YUV420SP;
3047a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.YUY2:      return PIXEL_FORMAT_YUV422I;
304810a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            case ImageFormat.YV12:      return PIXEL_FORMAT_YUV420P;
3049a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.RGB_565:   return PIXEL_FORMAT_RGB565;
3050a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.JPEG:      return PIXEL_FORMAT_JPEG;
3051a696f5d667227365da732481770767dcb330dd23Mathias Agopian            default:                    return null;
30529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
30539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
30549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private int pixelFormatForCameraFormat(String format) {
30569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (format == null)
3057a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.UNKNOWN;
30589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV422SP))
3060a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV16;
30619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420SP))
3063a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV21;
30649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3065eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            if (format.equals(PIXEL_FORMAT_YUV422I))
3066a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.YUY2;
3067eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang
306810a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420P))
306910a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li                return ImageFormat.YV12;
307010a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li
30719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_RGB565))
3072a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.RGB_565;
30739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_JPEG))
3075a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.JPEG;
30769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3077a696f5d667227365da732481770767dcb330dd23Mathias Agopian            return ImageFormat.UNKNOWN;
30789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
30799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30818969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * Sets the clockwise rotation angle in degrees relative to the
30828969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * orientation of the camera. This affects the pictures returned from
30838969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * JPEG {@link PictureCallback}. The camera driver may set orientation
30848969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * in the EXIF header without rotating the picture. Or the driver may
30858969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
3086a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotated, the orientation in the EXIF header will be missing or 1 (row
3087a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * #0 is top and column #0 is left side).
3088a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
3089a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
3090a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * If applications want to rotate the picture to match the orientation
3091a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * of what users see, apps should use
3092a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.view.OrientationEventListener} and
3093a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.hardware.Camera.CameraInfo}. The value from
3094a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * OrientationEventListener is relative to the natural orientation of
3095a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the device. CameraInfo.orientation is the angle between camera
3096a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * orientation and natural device orientation. The sum of the two is the
3097a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotation angle for back-facing camera. The difference of the two is
3098a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the rotation angle for front-facing camera. Note that the JPEG
3099a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * pictures of front-facing cameras are not mirrored as in preview
3100a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * display.
3101a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
3102a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
3103a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * For example, suppose the natural orientation of the device is
31042fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * portrait. The device is rotated 270 degrees clockwise, so the device
31052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 270. Suppose a back-facing camera sensor is mounted in
31062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * landscape and the top side of the camera sensor is aligned with the
31072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the display in natural orientation. So the camera
31082fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 90. The rotation should be set to 0 (270 + 90).
31092fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
311069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>The reference code is as follows.
31112fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
3112e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * <pre>
31139a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main         * public void onOrientationChanged(int orientation) {
31142fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     if (orientation == ORIENTATION_UNKNOWN) return;
31152fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.CameraInfo info =
31162fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *            new android.hardware.Camera.CameraInfo();
31172fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.getCameraInfo(cameraId, info);
31182fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     orientation = (orientation + 45) / 90 * 90;
31192fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     int rotation = 0;
31202fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
31212fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation - orientation + 360) % 360;
31222fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     } else {  // back-facing camera
31232fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation + orientation) % 360;
31242fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     }
31252fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     mParameters.setRotation(rotation);
31262fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * }
3127e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * </pre>
31282fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
31292fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @param rotation The rotation angle in degrees relative to the
31302fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 orientation of the camera. Rotation can only be 0,
31312fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 90, 180 or 270.
31329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @throws IllegalArgumentException if rotation value is invalid.
31339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @see android.view.OrientationEventListener
31342fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
31359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setRotation(int rotation) {
31379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (rotation == 0 || rotation == 90 || rotation == 180
31389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                    || rotation == 270) {
31399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                set(KEY_ROTATION, Integer.toString(rotation));
31409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            } else {
31419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
31429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid rotation=" + rotation);
31439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
31449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
31479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
31489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
31499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param latitude GPS latitude coordinate.
31519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLatitude(double latitude) {
31539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LATITUDE, Double.toString(latitude));
31549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
31579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
31589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
31599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param longitude GPS longitude coordinate.
31619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLongitude(double longitude) {
31639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LONGITUDE, Double.toString(longitude));
31649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
31679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS altitude. This will be stored in JPEG EXIF header.
31689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param altitude GPS altitude in meters.
31709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsAltitude(double altitude) {
31729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_ALTITUDE, Double.toString(altitude));
31739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
31769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS timestamp. This will be stored in JPEG EXIF header.
31779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param timestamp GPS timestamp (UTC in seconds since January 1,
31799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                  1970).
31809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsTimestamp(long timestamp) {
31829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
31839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3186e208377fbab6b90f41e68699700942a81f4caaebRay Chen         * Sets GPS processing method. It will store up to 32 characters
3187055c986ab841f8f758398841730f1e90313b132aRay Chen         * in JPEG EXIF header.
3188055c986ab841f8f758398841730f1e90313b132aRay Chen         *
3189055c986ab841f8f758398841730f1e90313b132aRay Chen         * @param processing_method The processing method to get this location.
3190055c986ab841f8f758398841730f1e90313b132aRay Chen         */
3191055c986ab841f8f758398841730f1e90313b132aRay Chen        public void setGpsProcessingMethod(String processing_method) {
3192055c986ab841f8f758398841730f1e90313b132aRay Chen            set(KEY_GPS_PROCESSING_METHOD, processing_method);
3193055c986ab841f8f758398841730f1e90313b132aRay Chen        }
3194055c986ab841f8f758398841730f1e90313b132aRay Chen
3195055c986ab841f8f758398841730f1e90313b132aRay Chen        /**
31969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Removes GPS latitude, longitude, altitude, and timestamp from the
31979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * parameters.
31989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void removeGpsData() {
32009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LATITUDE);
32019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LONGITUDE);
32029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_ALTITUDE);
32039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_TIMESTAMP);
3204055c986ab841f8f758398841730f1e90313b132aRay Chen            remove(KEY_GPS_PROCESSING_METHOD);
32059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current white balance setting.
32099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current white balance. null if white balance setting is not
32113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
32123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_AUTO
32133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_INCANDESCENT
32143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_FLUORESCENT
32153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_WARM_FLUORESCENT
32163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_DAYLIGHT
32173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
32183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_TWILIGHT
32193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_SHADE
32203f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *
32219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getWhiteBalance() {
32239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_WHITE_BALANCE);
32249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
322716b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * Sets the white balance. Changing the setting will release the
3228b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * auto-white balance lock. It is recommended not to change white
3229b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * balance and AWB lock at the same time.
32309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new white balance.
32323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
3233037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
32349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setWhiteBalance(String value) {
3236b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            String oldValue = get(KEY_WHITE_BALANCE);
3237b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (same(value, oldValue)) return;
32389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_WHITE_BALANCE, value);
323916b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
32409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported white balance.
32449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported white balance. null if white balance
32463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
32473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
32489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedWhiteBalance() {
32509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
32519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
32529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current color effect setting.
32569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32573f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current color effect. null if color effect
32589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
32593f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NONE
32603f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_MONO
32613f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NEGATIVE
32623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SOLARIZE
32633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SEPIA
32643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_POSTERIZE
32653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_WHITEBOARD
32663f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_BLACKBOARD
32673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_AQUA
32689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getColorEffect() {
32709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_EFFECT);
32719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the current color effect setting.
32759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32763f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new color effect.
32773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
32789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setColorEffect(String value) {
32809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_EFFECT, value);
32819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported color effects.
32859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported color effects. null if color effect
32879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
32883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
32899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedColorEffects() {
32919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
32929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
32939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current antibanding setting.
32989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current antibanding. null if antibanding setting is not
33003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
33013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_AUTO
33023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_50HZ
33033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_60HZ
33043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_OFF
33059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getAntibanding() {
33079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_ANTIBANDING);
33089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the antibanding.
33129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param antibanding new antibanding value.
33143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
33159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setAntibanding(String antibanding) {
33179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_ANTIBANDING, antibanding);
33189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported antibanding values.
33229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported antibanding values. null if antibanding
33243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
33253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
33269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedAntibanding() {
33289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
33299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
33309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current scene mode setting.
33349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return one of SCENE_MODE_XXX string constant. null if scene mode
33369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
33373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_AUTO
33383f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_ACTION
33393f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PORTRAIT
33403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_LANDSCAPE
33413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT
33423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT_PORTRAIT
33433f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_THEATRE
33443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_BEACH
33453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SNOW
33463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SUNSET
33473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_STEADYPHOTO
33483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_FIREWORKS
33493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SPORTS
33503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PARTY
33513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_CANDLELIGHT
3352da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * @see #SCENE_MODE_BARCODE
33539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getSceneMode() {
33559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_SCENE_MODE);
33569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3359c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Sets the scene mode. Changing scene mode may override other
3360c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * parameters (such as flash mode, focus mode, white balance). For
3361c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * example, suppose originally flash mode is on and supported flash
3362c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * modes are on/off. In night scene mode, both flash mode and supported
3363c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * flash mode may be changed to off. After setting scene mode,
33642988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * applications should call getParameters to know if some parameters are
33652988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * changed.
33669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value scene mode.
33683f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
33699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setSceneMode(String value) {
33719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_SCENE_MODE, value);
33729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported scene modes.
33769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported scene modes. null if scene mode setting
33783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
33793f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
33809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedSceneModes() {
33829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
33839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
33849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current flash mode setting.
33889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current flash mode. null if flash mode setting is not
33903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
33913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_OFF
33923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_AUTO
33933f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_ON
33943f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_RED_EYE
33953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_TORCH
33969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getFlashMode() {
33989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_FLASH_MODE);
33999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the flash mode.
34039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value flash mode.
34053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
34069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setFlashMode(String value) {
34089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_FLASH_MODE, value);
34099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported flash modes.
34139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported flash modes. null if flash mode setting
34153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
34163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
34179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedFlashModes() {
34199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
34209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
34219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
342336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
342436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the current focus mode setting.
342536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
3426699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * @return current focus mode. This method will always return a non-null
3427699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         value. Applications should call {@link
3428699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         #autoFocus(AutoFocusCallback)} to start the focus if focus
3429699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
34303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_AUTO
34313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_INFINITY
34323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_MACRO
34333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_FIXED
3434f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * @see #FOCUS_MODE_EDOF
3435d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
343636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
343736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public String getFocusMode() {
343836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return get(KEY_FOCUS_MODE);
343936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
344036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
344136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
344236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Sets the focus mode.
344336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
34443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value focus mode.
34453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
344636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
344736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public void setFocusMode(String value) {
344836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            set(KEY_FOCUS_MODE, value);
344936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
345036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
345136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
345236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the supported focus modes.
345336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
34543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported focus modes. This method will always
34553f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
34563f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
345736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
345836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public List<String> getSupportedFocusModes() {
345936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
346036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return split(str);
346136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
346236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
346336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
34646c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the focal length (in millimeter) of the camera.
34656c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
34666c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return the focal length. This method will always return a valid
34676c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         value.
34686c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
34696c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getFocalLength() {
34706c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_FOCAL_LENGTH));
34716c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
34726c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
34736c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
34746c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the horizontal angle of view in degrees.
34756c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
34766c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return horizontal angle of view. This method will always return a
34776c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
34786c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
34796c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getHorizontalViewAngle() {
34806c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
34816c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
34826c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
34836c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
34846c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the vertical angle of view in degrees.
34856c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
34866c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return vertical angle of view. This method will always return a
34876c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
34886c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
34896c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getVerticalViewAngle() {
34906c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
34916c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
34926c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
34936c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
349424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the current exposure compensation index.
3495ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
349624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return current exposure compensation index. The range is {@link
349724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMinExposureCompensation} to {@link
349824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMaxExposureCompensation}. 0 means exposure is not
349924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         adjusted.
3500ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3501ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public int getExposureCompensation() {
350224b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_EXPOSURE_COMPENSATION, 0);
3503ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3504ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3505ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
350624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Sets the exposure compensation index.
3507ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
35080402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         * @param value exposure compensation index. The valid value range is
35090402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         *        from {@link #getMinExposureCompensation} (inclusive) to {@link
351024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        #getMaxExposureCompensation} (inclusive). 0 means exposure is
351124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        not adjusted. Application should call
351224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        getMinExposureCompensation and getMaxExposureCompensation to
351324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        know if exposure compensation is supported.
3514ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3515ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public void setExposureCompensation(int value) {
3516ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li            set(KEY_EXPOSURE_COMPENSATION, value);
3517ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3518ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3519ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
352024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the maximum exposure compensation index.
3521ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
352224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return maximum exposure compensation index (>=0). If both this
352324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMinExposureCompensation} return 0,
352424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
352524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
352624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMaxExposureCompensation() {
352724b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
352824b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
352924b326a8978bf78e3e560723dde221792784325bWu-cheng Li
353024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
353124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the minimum exposure compensation index.
353224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
353324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return minimum exposure compensation index (<=0). If both this
353424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMaxExposureCompensation} return 0,
353524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
3536ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
353724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMinExposureCompensation() {
353824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
353924b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
354024b326a8978bf78e3e560723dde221792784325bWu-cheng Li
354124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
354224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the exposure compensation step.
354324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
354424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return exposure compensation step. Applications can get EV by
354524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         multiplying the exposure compensation index and step. Ex: if
354624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation index is -6 and step is 0.333333333, EV
354724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         is -2.
354824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
354924b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public float getExposureCompensationStep() {
355024b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
3551ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3552ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3553ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
3554d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-exposure lock state. Applications should check
3555d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method.</p>
35563773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3557d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-exposure routine will immediately
3558d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * pause until the lock is set to false. Exposure compensation settings
3559d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * changes will still take effect while auto-exposure is locked.</p>
3560d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3561d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-exposure is already locked, setting this to true again has
3562d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * no effect (the driver will not recalculate exposure values).</p>
3563d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3564d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3565d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3566b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3567b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock.</p>
3568d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3569b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3570b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock can be used to capture an exposure-bracketed burst of images,
3571b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * for example.</p>
3572d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3573d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Auto-exposure state, including the lock state, will not be
35743773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * maintained after camera {@link #release()} is called.  Locking
35753773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * auto-exposure after {@link #open()} but before the first call to
35763773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #startPreview()} will not allow the auto-exposure routine to
3577d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * run at all, and may result in severely over- or under-exposed
3578d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * images.</p>
35793773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
35803773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @param toggle new state of the auto-exposure lock. True means that
35813773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        auto-exposure is locked, false means that the auto-exposure
35823773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        routine is free to run normally.
35833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3584d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoExposureLock()
35853773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
35863773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public void setAutoExposureLock(boolean toggle) {
35873773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
35883773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
35893773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
35903773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
35913773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Gets the state of the auto-exposure lock. Applications should check
35923773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method. See
35933773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
35943773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
35953773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return State of the auto-exposure lock. Returns true if
3596b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         auto-exposure is currently locked, and false otherwise.
35973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
35983773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
35993773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
36003773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
36013773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean getAutoExposureLock() {
36023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK);
36033773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
36043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
36053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
36063773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
36073773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Returns true if auto-exposure locking is supported. Applications
36083773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * should call this before trying to lock auto-exposure. See
36093773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
36103773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
36113773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return true if auto-exposure lock is supported.
36123773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
36133773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
36143773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
36153773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean isAutoExposureLockSupported() {
36163773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
36173773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
36183773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
36193773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
36203773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
3621d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-white balance lock state. Applications should check
3622d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoWhiteBalanceLockSupported} before using this
3623d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method.</p>
3624d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3625d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-white balance routine will
3626d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * immediately pause until the lock is set to false.</p>
3627d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3628d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-white balance is already locked, setting this to true
3629d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * again has no effect (the driver will not recalculate white balance
3630d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * values).</p>
3631d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3632d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3633d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3634b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3635b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * the lock.</p>
3636d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
363716b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * <p> Changing the white balance mode with {@link #setWhiteBalance}
363816b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * will release the auto-white balance lock if it is set.</p>
363916b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         *
3640b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, AE lock, and AWB lock can be used to
3641b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * capture an exposure-bracketed burst of images, for example.
3642b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Auto-white balance state, including the lock state, will not be
3643b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * maintained after camera {@link #release()} is called.  Locking
3644b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * auto-white balance after {@link #open()} but before the first call to
3645b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * {@link #startPreview()} will not allow the auto-white balance routine
3646b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * to run at all, and may result in severely incorrect color in captured
3647b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * images.</p>
3648d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3649d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @param toggle new state of the auto-white balance lock. True means
3650d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        that auto-white balance is locked, false means that the
3651d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        auto-white balance routine is free to run normally.
3652d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3653d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoWhiteBalanceLock()
365416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * @see #setWhiteBalance(String)
3655d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3656d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public void setAutoWhiteBalanceLock(boolean toggle) {
3657d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3658d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3659d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3660d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3661d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Gets the state of the auto-white balance lock. Applications should
3662d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * check {@link #isAutoWhiteBalanceLockSupported} before using this
3663d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method. See {@link #setAutoWhiteBalanceLock} for details about the
3664d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * lock.
3665d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3666d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return State of the auto-white balance lock. Returns true if
3667d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *         auto-white balance is currently locked, and false
3668b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         otherwise.
3669d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3670d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3671d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3672d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3673d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean getAutoWhiteBalanceLock() {
3674d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3675d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3676d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3677d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3678d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3679d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Returns true if auto-white balance locking is supported. Applications
3680d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * should call this before trying to lock auto-white balance. See
3681d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #setAutoWhiteBalanceLock} for details about the lock.
3682d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3683d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return true if auto-white balance lock is supported.
3684d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3685d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3686d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3687d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean isAutoWhiteBalanceLockSupported() {
3688d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3689d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3690d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3691d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3692d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
369336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets current zoom value. This also works when smooth zoom is in
36948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * progress. Applications should check {@link #isZoomSupported} before
36958cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * using this method.
369636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
369736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the current zoom value. The range is 0 to {@link
36988cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom}. 0 means the camera is not zoomed.
369936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
370036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getZoom() {
37018cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_ZOOM, 0);
370236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
370336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
370436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
37058cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Sets current zoom value. If the camera is zoomed (value > 0), the
37068cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * actual picture size may be smaller than picture size setting.
37078cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications can check the actual picture size after picture is
37088cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * returned from {@link PictureCallback}. The preview size remains the
37098cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * same in zoom. Applications should check {@link #isZoomSupported}
37108cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * before using this method.
371136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
371236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
371336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
371436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public void setZoom(int value) {
37158cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            set(KEY_ZOOM, value);
371636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
371736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
371836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
371936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if zoom is supported. Applications should call this
372036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * before using other zoom methods.
372136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
372236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if zoom is supported.
372336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
372436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isZoomSupported() {
37258cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_ZOOM_SUPPORTED);
37268cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
372736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
372836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
372936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
373036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets the maximum zoom value allowed for snapshot. This is the maximum
373136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * value that applications can set to {@link #setZoom(int)}.
37328cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications should call {@link #isZoomSupported} before using this
37338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * method. This value may change in different preview size. Applications
37348cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * should call this again after setting preview size.
373536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
373636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the maximum zoom value supported by the camera.
373736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
373836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getMaxZoom() {
37398cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_MAX_ZOOM, 0);
374036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
374136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
374236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
37438cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Gets the zoom ratios of all zoom values. Applications should check
37448cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * {@link #isZoomSupported} before using this method.
374536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
37468cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
37478cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         returned as 320. The number of elements is {@link
37488cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom} + 1. The list is sorted from small to large. The
37498cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         first element is always 100. The last element is the zoom
37508cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         ratio of the maximum zoom value.
375136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
37528cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        public List<Integer> getZoomRatios() {
37538cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return splitInt(get(KEY_ZOOM_RATIOS));
375436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
375536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
375636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
375736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if smooth zoom is supported. Applications should call
375836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * this before using other smooth zoom methods.
375936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
376036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if smooth zoom is supported.
376136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
376236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isSmoothZoomSupported() {
37638cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
37648cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
376536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
376636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
3767e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
376832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the distances from the camera to where an object appears to be
3769e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * in focus. The object is sharpest at the optimal focus distance. The
377032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * depth of field is the far focus distance minus near focus distance.</p>
3771e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
377232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus distances may change after calling {@link
3773e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3774e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #startPreview()}. Applications can call {@link #getParameters()}
3775e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * and this method anytime to get the latest focus distances. If the
3776d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
377732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * from time to time.</p>
3778699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *
377932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>This method is intended to estimate the distance between the camera
3780699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * and the subject. After autofocus, the subject distance may be within
3781699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * near and far focus distance. However, the precision depends on the
3782699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * camera hardware, autofocus algorithm, the focus area, and the scene.
378332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * The error can be large and it should be only used as a reference.</p>
3784e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
378532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Far focus distance >= optimal focus distance >= near focus distance.
3786185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * If the focus distance is infinity, the value will be
378732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * {@code Float.POSITIVE_INFINITY}.</p>
3788e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
3789e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * @param output focus distances in meters. output must be a float
3790e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        array with three elements. Near focus distance, optimal focus
3791e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        distance, and far focus distance will be filled in the array.
3792185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_NEAR_INDEX
3793185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3794185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_FAR_INDEX
3795e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
3796e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public void getFocusDistances(float[] output) {
3797e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            if (output == null || output.length != 3) {
3798e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                throw new IllegalArgumentException(
3799f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa                        "output must be a float array with three elements.");
3800e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3801454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitFloat(get(KEY_FOCUS_DISTANCES), output);
3802e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3803e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
380430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
380530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Gets the maximum number of focus areas supported. This is the maximum
38067b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * length of the list in {@link #setFocusAreas(List)} and
38077b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getFocusAreas()}.
380830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
380930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return the maximum number of focus areas supported by the camera.
381030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
381130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
381230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int getMaxNumFocusAreas() {
381330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
381430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
381530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
381630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
381732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current focus areas. Camera driver uses the areas to decide
381832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus.</p>
381930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
382032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
38217b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumFocusAreas()} to know the maximum number of
382232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus areas first. If the value is 0, focus area is not supported.</p>
382330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
382432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each focus area is a rectangle with specified weight. The direction
382530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * is relative to the sensor orientation, that is, what the sensor sees.
382630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * The direction is not affected by the rotation or mirroring of
382730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
382830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * range from -1000 to 1000. (-1000, -1000) is the upper left point.
3829bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * (1000, 1000) is the lower right point. The width and height of focus
383032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * areas cannot be 0 or negative.</p>
383130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
383232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000. The weight should be
38334e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * interpreted as a per-pixel weight - all pixels in the area have the
38344e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * specified weight. This means a small area with the same weight as a
38354e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * larger area will have less influence on the focusing than the larger
38364e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * area. Focus areas can partially overlap and the driver will add the
383732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * weights in the overlap region.</p>
383830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
383932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} focus area list means the driver is
384032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * free to select focus targets as it wants. For example, the driver may
384132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * use more signals to select focus areas and change them
384232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * dynamically. Apps can set the focus area list to {@code null} if they
384332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * want the driver to completely control focusing.</p>
384430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
384532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus areas are relative to the current field of view
384630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
384730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * represents the top of the currently visible camera frame. The focus
384830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * area cannot be set to be outside the current field of view, even
384932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * when using zoom.</p>
385030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
385132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus area only has effect if the current focus mode is
385253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
385353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
385453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
385530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
385630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return a list of current focus areas
385730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
385830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public List<Area> getFocusAreas() {
3859f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            return splitArea(get(KEY_FOCUS_AREAS));
386030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
386130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
386230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
386330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Sets focus areas. See {@link #getFocusAreas()} for documentation.
386430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
38657b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param focusAreas the focus areas
386630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
386730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
3868e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setFocusAreas(List<Area> focusAreas) {
3869e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_FOCUS_AREAS, focusAreas);
3870e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3871e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3872e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3873e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Gets the maximum number of metering areas supported. This is the
38747b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * maximum length of the list in {@link #setMeteringAreas(List)} and
38757b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getMeteringAreas()}.
3876e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3877e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return the maximum number of metering areas supported by the camera.
3878e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3879e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3880e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public int getMaxNumMeteringAreas() {
3881e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3882e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3883e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3884e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
388532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current metering areas. Camera driver uses these areas to
388632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * decide exposure.</p>
3887e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
388832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
38897b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
38907b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * metering areas first. If the value is 0, metering area is not
389132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * supported.</p>
3892e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
389332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each metering area is a rectangle with specified weight. The
3894e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * direction is relative to the sensor orientation, that is, what the
3895e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * sensor sees. The direction is not affected by the rotation or
3896e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3897e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
3898bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * point. (1000, 1000) is the lower right point. The width and height of
389932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * metering areas cannot be 0 or negative.</p>
3900e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
390132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000, and represents a weight for
39024e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * every pixel in the area. This means that a large metering area with
39034e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * the same weight as a smaller area will have more effect in the
39044e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * metering result.  Metering areas can partially overlap and the driver
390532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * will add the weights in the overlap region.</p>
3906e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
390732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} metering area list means the driver
390832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * is free to meter as it chooses. For example, the driver may use more
390932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * signals to select metering areas and change them dynamically. Apps
391032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * can set the metering area list to {@code null} if they want the
391132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * driver to completely control metering.</p>
3912e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
391332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Metering areas are relative to the current field of view
3914e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3915e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * represents the top of the currently visible camera frame. The
3916e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * metering area cannot be set to be outside the current field of view,
391732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * even when using zoom.</p>
3918e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
391932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>No matter what metering areas are, the final exposure are compensated
392032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * by {@link #setExposureCompensation(int)}.</p>
3921e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3922e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return a list of current metering areas
3923e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3924e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public List<Area> getMeteringAreas() {
3925d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li            return splitArea(get(KEY_METERING_AREAS));
3926e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3927e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3928e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3929e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Sets metering areas. See {@link #getMeteringAreas()} for
3930e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * documentation.
3931e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
39327b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param meteringAreas the metering areas
3933e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3934e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3935e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setMeteringAreas(List<Area> meteringAreas) {
3936e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_METERING_AREAS, meteringAreas);
393730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
393830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
39394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
39404c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Gets the maximum number of detected faces supported. This is the
39414c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * maximum length of the list returned from {@link FaceDetectionListener}.
39424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * If the return value is 0, face detection of the specified type is not
39434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * supported.
39444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
39454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * @return the maximum number of detected face supported by the camera.
3946464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
39474c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
3948c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        public int getMaxNumDetectedFaces() {
3949c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li            return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
39504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
39514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
395225d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        /**
39539c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Sets recording mode hint. This tells the camera that the intent of
39549c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * the application is to record videos {@link
39559c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * android.media.MediaRecorder#start()}, not to take still pictures
39569c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
39579c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
39589c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * allow MediaRecorder.start() to start faster or with fewer glitches on
39599c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * output. This should be called before starting preview for the best
39609c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * result, but can be changed while the preview is active. The default
39619c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * value is false.
39629c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
39639c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * The app can still call takePicture() when the hint is true or call
39649c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * MediaRecorder.start() when the hint is false. But the performance may
39659c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * be worse.
39669c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
39679c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * @param hint true if the apps intend to record videos using
396825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         *             {@link android.media.MediaRecorder}.
396925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         */
397025d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        public void setRecordingHint(boolean hint) {
397125d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li            set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
397225d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        }
397325d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li
397498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        /**
39751cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Returns true if video snapshot is supported. That is, applications
397698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * can call {@link #takePicture(Camera.ShutterCallback,
39771cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback, Camera.PictureCallback,
39781cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback)} during recording. Applications do not need
39791cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * to call {@link #startPreview()} after taking a picture. The preview
39801cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * will be still active. Other than that, taking a picture during
39811cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * recording is identical to taking a picture normally. All settings and
39821cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * methods related to takePicture work identically. Ex:
39831cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
39841cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
39851cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
39861cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #FLASH_MODE_ON} also still work, but the video will record the
39871cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * flash.</p>
39881cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         *
39891cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Applications can set shutter callback as null to avoid the shutter
399098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * sound. It is also recommended to set raw picture and post view
39911cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * callbacks to null to avoid the interrupt of preview display.</p>
399298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
39931cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Field-of-view of the recorded video may be different from that of the
39941cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * captured pictures. The maximum size of a video snapshot may be
39951cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * smaller than that for regular still captures. If the current picture
39961cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * size is set higher than can be supported by video snapshot, the
39971cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will be captured at the maximum supported size instead.</p>
399898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
399998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * @return true if video snapshot is supported.
400098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         */
400198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        public boolean isVideoSnapshotSupported() {
400298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
400398bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            return TRUE.equals(str);
400498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        }
400598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li
4006037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4007037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Enables and disables video stabilization. Use
4008037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #isVideoStabilizationSupported} to determine if calling this
4009037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * method is valid.</p>
4010037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4011037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization reduces the shaking due to the motion of the
4012037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * camera in both the preview stream and in recorded videos, including
4013037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * data received from the preview callback. It does not reduce motion
4014037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * blur in images captured with
4015037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link Camera#takePicture takePicture}.</p>
4016037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4017037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization can be enabled and disabled while preview or
4018037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * recording is active, but toggling it may cause a jump in the video
4019037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * stream that may be undesirable in a recorded video.</p>
4020037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4021037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @param toggle Set to true to enable video stabilization, and false to
4022037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * disable video stabilization.
4023037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
4024037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
4025037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4026037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public void setVideoStabilization(boolean toggle) {
4027037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
4028037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4029037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
4030037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4031037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Get the current state of video stabilization. See
4032037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
4033037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4034037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is enabled
4035037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
4036037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
4037037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4038037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean getVideoStabilization() {
4039037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION);
4040037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
4041037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4042037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
4043037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4044037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Returns true if video stabilization is supported. See
4045037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
4046037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4047037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is supported
4048037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
4049037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
4050037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4051037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean isVideoStabilizationSupported() {
4052037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
4053037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
4054037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4055037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
40569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of String.
40579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
40589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<String> split(String str) {
40599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
40609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
40610a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
40620a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
40639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<String> substrings = new ArrayList<String>();
40640a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
40650a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(s);
40669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
40679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
40689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
40699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
40709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Integer.
40719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
40729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Integer> splitInt(String str) {
40739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
40749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
40750a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
40760a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
40779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Integer> substrings = new ArrayList<Integer>();
40780a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
40790a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(Integer.parseInt(s));
40809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
40819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (substrings.size() == 0) return null;
40829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
40839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
40849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4085454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitInt(String str, int[] output) {
4086454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
4087454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
40880a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
40890a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
4090454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
40910a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
40920a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Integer.parseInt(s);
4093454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
4094454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
4095454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4096e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Splits a comma delimited string to an ArrayList of Float.
4097454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitFloat(String str, float[] output) {
4098454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
4099e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
41000a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
41010a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
4102454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
41030a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
41040a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Float.parseFloat(s);
4105e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
4106e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
4107e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
410824b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a float parameter.
410924b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private float getFloat(String key, float defaultValue) {
411024b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
411124b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Float.parseFloat(mMap.get(key));
411224b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
411324b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
411424b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
411524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
411624b326a8978bf78e3e560723dde221792784325bWu-cheng Li
411724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a integer parameter.
411824b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private int getInt(String key, int defaultValue) {
411924b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
412024b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Integer.parseInt(mMap.get(key));
412124b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
412224b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
412324b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
412424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
412524b326a8978bf78e3e560723dde221792784325bWu-cheng Li
41269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Size.
41279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
41289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Size> splitSize(String str) {
41299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
41309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
41310a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
41320a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
41339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Size> sizeList = new ArrayList<Size>();
41340a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
41350a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                Size size = strToSize(s);
41369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                if (size != null) sizeList.add(size);
41379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
41389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (sizeList.size() == 0) return null;
41399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return sizeList;
41409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
41419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
41429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parses a string (ex: "480x320") to Size object.
41439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null.
41449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private Size strToSize(String str) {
41459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
41469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
41479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            int pos = str.indexOf('x');
41489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (pos != -1) {
41499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String width = str.substring(0, pos);
41509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String height = str.substring(pos + 1);
41519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                return new Size(Integer.parseInt(width),
41529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                                Integer.parseInt(height));
41539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
41549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            Log.e(TAG, "Invalid size parameter string=" + str);
41559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return null;
41569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
4157454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4158454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Splits a comma delimited string to an ArrayList of int array.
4159454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Example string: "(10000,26623),(10000,30000)". Return null if the
4160454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // passing string is null or the size is 0.
4161454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private ArrayList<int[]> splitRange(String str) {
4162454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null || str.charAt(0) != '('
4163454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
4164454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                Log.e(TAG, "Invalid range list string=" + str);
4165454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                return null;
4166454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
4167454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4168454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            ArrayList<int[]> rangeList = new ArrayList<int[]>();
4169454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int endIndex, fromIndex = 1;
4170454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            do {
4171454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                int[] range = new int[2];
4172454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
4173454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
4174454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                splitInt(str.substring(fromIndex, endIndex), range);
4175454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                rangeList.add(range);
4176454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                fromIndex = endIndex + 3;
4177454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            } while (endIndex != str.length() - 1);
4178454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4179454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (rangeList.size() == 0) return null;
4180454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return rangeList;
4181454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
418230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
418330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Splits a comma delimited string to an ArrayList of Area objects.
418430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
4185f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li        // the passing string is null or the size is 0 or (0,0,0,0,0).
418630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private ArrayList<Area> splitArea(String str) {
418730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (str == null || str.charAt(0) != '('
418830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
418930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Log.e(TAG, "Invalid area string=" + str);
419030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return null;
419130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
419230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
419330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            ArrayList<Area> result = new ArrayList<Area>();
419430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int endIndex, fromIndex = 1;
419530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int[] array = new int[5];
419630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            do {
419730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
419830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
419930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                splitInt(str.substring(fromIndex, endIndex), array);
420030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Rect rect = new Rect(array[0], array[1], array[2], array[3]);
420130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                result.add(new Area(rect, array[4]));
420230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                fromIndex = endIndex + 3;
420330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } while (endIndex != str.length() - 1);
420430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
420530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (result.size() == 0) return null;
4206f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
4207f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (result.size() == 1) {
4208bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li                Area area = result.get(0);
4209f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                Rect rect = area.rect;
4210f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                if (rect.left == 0 && rect.top == 0 && rect.right == 0
4211f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                        && rect.bottom == 0 && area.weight == 0) {
4212f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    return null;
4213f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
4214f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            }
4215f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
421630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return result;
421730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
4218b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li
4219b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        private boolean same(String s1, String s2) {
4220b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 == null && s2 == null) return true;
4221b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 != null && s1.equals(s2)) return true;
4222b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            return false;
4223b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        }
42249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
42259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4226