Camera.java revision e059e45b053454deb1044123a5a65ba725fb952c
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
1906a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvalaimport static android.system.OsConstants.*;
2006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala
21503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport android.annotation.Nullable;
2210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant;
2310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant.SdkConstantType;
2406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvalaimport android.app.ActivityThread;
25503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport android.app.AppOpsManager;
264f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.content.Context;
27a696f5d667227365da732481770767dcb330dd23Mathias Agopianimport android.graphics.ImageFormat;
284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Liimport android.graphics.Point;
2930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Liimport android.graphics.Rect;
30fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennisimport android.graphics.SurfaceTexture;
31503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport android.media.AudioAttributes;
324f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.media.IAudioService;
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
344f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.IBinder;
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper;
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message;
37503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport android.os.Process;
384f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.RemoteException;
394f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.ServiceManager;
407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Allocation;
417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Element;
427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.RSIllegalArgumentException;
4306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvalaimport android.renderscript.RenderScript;
447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Type;
450a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selenimport android.text.TextUtils;
4606a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvalaimport android.util.Log;
47bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.Surface;
48bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.SurfaceHolder;
49bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li
50503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport com.android.internal.annotations.GuardedBy;
51503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport com.android.internal.app.IAppOpsCallback;
52503e1fdcd12d2448807d408f00a361bff0857cabjiabinimport com.android.internal.app.IAppOpsService;
53503e1fdcd12d2448807d408f00a361bff0857cabjiabin
54bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.io.IOException;
55bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.lang.ref.WeakReference;
56bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.ArrayList;
577d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkinimport java.util.LinkedHashMap;
58bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.List;
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
61bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The Camera class is used to set image capture settings, start/stop preview,
62bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * snap pictures, and retrieve frames for encoding for video.  This class is a
63bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * client for the Camera service, which manages the actual camera hardware.
64df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
65bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To access the device camera, you must declare the
667478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * {@link android.Manifest.permission#CAMERA} permission in your Android
67df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * Manifest. Also be sure to include the
68df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
69bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * manifest element to declare camera features used by your application.
707478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * For example, if you use the camera and auto-focus feature, your Manifest
71df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * should include the following:</p>
72df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
73df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera" />
74df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
75df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
76bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To take pictures with this class, use the following steps:</p>
77bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
78bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
79341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * <li>Obtain an instance of Camera from {@link #open(int)}.
80bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
81bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Get existing (default) settings with {@link #getParameters()}.
82bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
83bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
84bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setParameters(Camera.Parameters)}.
85bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
866c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala * <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview.
87bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
88bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
89bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewDisplay(SurfaceHolder)}.  Without a surface, the camera
90bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * will be unable to start the preview.
91bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
92bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
93bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * preview surface.  Preview must be started before you can take a picture.
94bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
95bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
96bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
97bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * capture a photo.  Wait for the callbacks to provide the actual image data.
98bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
99bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>After taking a picture, preview display will have stopped.  To take more
100bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * photos, call {@link #startPreview()} again first.
101bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
102bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} to stop updating the preview surface.
103bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
104bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important:</b> Call {@link #release()} to release the camera for
105bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * use by other applications.  Applications should release the camera
106bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
107bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * it in {@link android.app.Activity#onResume()}).
108bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
109bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
110bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To quickly switch to video recording mode, use these steps:</p>
111bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
112bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
113bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Obtain and initialize a Camera and start preview as described above.
114bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
115bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #unlock()} to allow the media process to access the camera.
116bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
117bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
118bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * See {@link android.media.MediaRecorder} information about video recording.
119bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
120bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When finished recording, call {@link #reconnect()} to re-acquire
121bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * and re-lock the camera.
122bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
123bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, restart preview and take more photos or videos.
124bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
125bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
126bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
127bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
128bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This class is not thread-safe, and is meant for use from one event thread.
129bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Most long-running operations (preview, focus, photo capture, etc) happen
130bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * asynchronously and invoke callbacks as necessary.  Callbacks will be invoked
131341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * on the event thread {@link #open(int)} was called from.  This class's methods
132bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * must never be called from multiple threads at once.</p>
133bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
134df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
135df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * may have different hardware specifications, such as megapixel ratings and
136df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * auto-focus capabilities. In order for your application to be compatible with
1377478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * more devices, you should not make assumptions about the device camera
138df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * specifications.</p>
1396c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez *
1406c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <div class="special reference">
1416c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <h3>Developer Guides</h3>
1426c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <p>For more information about using cameras, read the
1436c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
1446c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * </div>
145b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala *
146b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
147b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala *             applications.
1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
149b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala@Deprecated
1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Camera {
1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final String TAG = "Camera";
1529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
153d2c2929c94bec68741b85f4174e11307fb65157fWu-cheng Li    // These match the enums in frameworks/base/include/camera/Camera.h
154da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ERROR            = 0x001;
155da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_SHUTTER          = 0x002;
156da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_FOCUS            = 0x004;
157da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ZOOM             = 0x008;
158da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_PREVIEW_FRAME    = 0x010;
159da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_VIDEO_FRAME      = 0x020;
160da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_POSTVIEW_FRAME   = 0x040;
161da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
162da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
1634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
164bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li    private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
1659d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private static final int CAMERA_MSG_FOCUS_MOVE       = 0x800;
1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1674838e338129e09a37b8c8ad5e44f85ec5cd3aea1Ashok Bhat    private long mNativeContext; // accessed by native methods
1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private EventHandler mEventHandler;
1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ShutterCallback mShutterCallback;
1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mRawImageCallback;
1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mJpegCallback;
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PreviewCallback mPreviewCallback;
1737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private boolean mUsingPreviewAllocation;
174e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    private PictureCallback mPostviewCallback;
1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private AutoFocusCallback mAutoFocusCallback;
1769d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private AutoFocusMoveCallback mAutoFocusMoveCallback;
1773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    private OnZoomChangeListener mZoomListener;
1784c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private FaceDetectionListener mFaceListener;
1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ErrorCallback mErrorCallback;
1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mOneShot;
18194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private boolean mWithBuffer;
1824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private boolean mFaceDetectionRunning = false;
183a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private final Object mAutoFocusCallbackLock = new Object();
1849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
185503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private final Object mShutterSoundLock = new Object();
186503e1fdcd12d2448807d408f00a361bff0857cabjiabin    // for AppOps
187503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private @Nullable IAppOpsService mAppOps;
188503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private IAppOpsCallback mAppOpsCallback;
189503e1fdcd12d2448807d408f00a361bff0857cabjiabin    @GuardedBy("mShutterSoundLock")
190503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private boolean mHasAppOpsPlayAudio = true;
191503e1fdcd12d2448807d408f00a361bff0857cabjiabin    @GuardedBy("mShutterSoundLock")
192503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private boolean mShutterSoundEnabledFromApp = true;
193503e1fdcd12d2448807d408f00a361bff0857cabjiabin
194feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    private static final int NO_ERROR = 0;
195feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
19710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new picture is taken by the camera, and the entry of
19810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * the picture has been added to the media store.
19910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the picture.
2005da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     *
2015da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and
2025da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * applications are recommended to use
2035da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
2045da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * instead.</p>
2055da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     *
2065da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought
2075da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * back, but only for <em>registered</em> receivers.  Apps that are actively running can
208c154195d27c51ffd8a3a114de5e462a8b1fdfa8bDianne Hackborn     * again listen to the broadcast if they want an immediate clear signal about a picture
2095da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * being taken, however anything doing heavy work (or needing to be launched) as a result of
2105da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * this should still use JobScheduler.</p>
21110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
21210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
21310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
21410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
21510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
21610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new video is recorded by the camera, and the entry
21710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * of the video has been added to the media store.
21810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the video.
2195da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     *
2205da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and
2215da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * applications are recommended to use
2225da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri}
2235da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * instead.</p>
2245da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     *
2255da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought
2265da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * back, but only for <em>registered</em> receivers.  Apps that are actively running can
227c154195d27c51ffd8a3a114de5e462a8b1fdfa8bDianne Hackborn     * again listen to the broadcast if they want an immediate clear signal about a video
2285da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * being taken, however anything doing heavy work (or needing to be launched) as a result of
2295da9e9495daf0cd1d353f1cdb9983908997bdfe3Dianne Hackborn     * this should still use JobScheduler.</p>
23010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
23110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
23210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
23310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
23410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
2354c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Camera HAL device API version 1.0
2364c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @hide
2374c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
2384c913801141163362dd5bb7c9784c83f69c11054Zhijun He    public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;
2394c913801141163362dd5bb7c9784c83f69c11054Zhijun He
2404c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2414c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * A constant meaning the normal camera connect/open will be used.
2424c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
243a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
2444c913801141163362dd5bb7c9784c83f69c11054Zhijun He
2454c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2464c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Used to indicate HAL version un-specified.
2474c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
2484c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
249a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
2504c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
2514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Hardware face detection. It does not use much CPU.
2524c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
253c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_HW = 0;
2544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
2554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
256c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Software face detection. It uses some CPU.
2574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
258c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_SW = 1;
2594c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
2604c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
261341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the number of physical cameras available on this device.
262564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh     * The return value of this method might change dynamically if the device
263564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh     * supports external cameras and an external camera is connected or
264564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh     * disconnected.
26506a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *
26606a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @return total number of accessible camera devices, or 0 if there are no
26706a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *   cameras or an error was encountered enumerating them.
268e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
269e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public native static int getNumberOfCameras();
270e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
271e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
272341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the information about a particular camera.
273b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
27406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *
27506a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if an invalid ID is provided, or if there is an
27606a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    error retrieving the information (generally due to a hardware or other
27706a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    low-level failure).
278b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
2794f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
2804f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        _getCameraInfo(cameraId, cameraInfo);
2814f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
2824f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IAudioService audioService = IAudioService.Stub.asInterface(b);
2834f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        try {
2844f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            if (audioService.isCameraSoundForced()) {
2854f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // Only set this when sound is forced; otherwise let native code
2864f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // decide.
2874f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                cameraInfo.canDisableShutterSound = false;
2884f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
2894f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        } catch (RemoteException e) {
2904f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            Log.e(TAG, "Audio service is unavailable for queries");
2914f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
2924f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
2934f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
294b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
295b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
296b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * Information about a camera
297b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
298b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
299b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
300b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
301b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
302b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    public static class CameraInfo {
3037836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
3047836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is opposite to that of the screen.
3057836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
306b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_BACK = 0;
3077836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li
3087836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
3097836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is the same as that of the screen.
3107836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
311b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_FRONT = 1;
312b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
313b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
314464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * The direction that the camera faces. It should be
315b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
316b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
3177836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int facing;
318b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
319b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
32032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The orientation of the camera image. The value is the angle that the
321b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * camera image needs to be rotated clockwise so it shows correctly on
32232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
323b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
32432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>For example, suppose a device has a naturally tall screen. The
3252fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * back-facing camera sensor is mounted in landscape. You are looking at
3262fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * the screen. If the top side of the camera sensor is aligned with the
3272fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the screen in natural orientation, the value should be
3282fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * 90. If the top side of a front-facing camera sensor is aligned with
32932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the right of the screen, the value should be 270.</p>
330b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
331b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * @see #setDisplayOrientation(int)
33269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setRotation(int)
33369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPreviewSize(int, int)
33469ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPictureSize(int, int)
33569ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setJpegThumbnailSize(int, int)
336b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
3377836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int orientation;
338f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala
339f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        /**
340f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>Whether the shutter sound can be disabled.</p>
341f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
342f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>On some devices, the camera shutter sound cannot be turned off
343f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * through {@link #enableShutterSound enableShutterSound}. This field
344f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * can be used to determine whether a call to disable the shutter sound
345f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * will succeed.</p>
346f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
347f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>If this field is set to true, then a call of
348f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * {@code enableShutterSound(false)} will be successful. If set to
349f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * false, then that call will fail, and the shutter sound will be played
350f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * when {@link Camera#takePicture takePicture} is called.</p>
351f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         */
352f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        public boolean canDisableShutterSound;
353b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    };
354b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
355b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
356a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * Creates a new Camera object to access a particular hardware camera. If
357a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * the same camera is opened by other applications, this will throw a
358a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * RuntimeException.
359a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *
360bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call {@link #release()} when you are done using the camera,
361bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * otherwise it will remain locked and be unavailable to other applications.
362bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
363341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * <p>Your application should only have one Camera object active at a time
364341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * for a particular hardware camera.
365bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
366bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callbacks from other methods are delivered to the event loop of the
367bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * thread which called open().  If this thread has no event loop, then
368bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callbacks are delivered to the main application event loop.  If there
369bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is no main application event loop, callbacks are not delivered.
370bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
371bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p class="caution"><b>Caution:</b> On some devices, this method may
372bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * take a long time to complete.  It is best to call this method from a
373bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
374bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * blocking the main application UI thread.
375bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
376341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * @param cameraId the hardware camera to access, between 0 and
377a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     *     {@link #getNumberOfCameras()}-1.
378bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @return a new Camera object, connected, locked and ready for use.
379a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * @throws RuntimeException if opening the camera fails (for example, if the
380a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     camera is in use by another process or device policy manager has
381a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     disabled the camera).
382facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
383e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
384e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public static Camera open(int cameraId) {
3857bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li        return new Camera(cameraId);
386e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    }
387e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
388e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
389a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * Creates a new Camera object to access the first back-facing camera on the
390a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * device. If the device does not have a back-facing camera, this returns
39106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * null. Otherwise acts like the {@link #open(int)} call.
39206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *
39306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @return a new Camera object for the first back-facing camera, or null if there is no
39406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *  backfacing camera
3957836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li     * @see #open(int)
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public static Camera open() {
398a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        int numberOfCameras = getNumberOfCameras();
399a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        CameraInfo cameraInfo = new CameraInfo();
400a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        for (int i = 0; i < numberOfCameras; i++) {
401a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            getCameraInfo(i, cameraInfo);
402a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
4037bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li                return new Camera(i);
404a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            }
405a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        }
406a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        return null;
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4094c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
4104c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Creates a new Camera object to access a particular hardware camera with
4114c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * given hal API version. If the same camera is opened by other applications
4124c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * or the hal API version is not supported by this device, this will throw a
4134c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * RuntimeException.
4144c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
4154c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * You must call {@link #release()} when you are done using the camera,
4164c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * otherwise it will remain locked and be unavailable to other applications.
4174c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
4184c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Your application should only have one Camera object active at a time for
4194c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * a particular hardware camera.
4204c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p>
4214c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Callbacks from other methods are delivered to the event loop of the
4224c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * thread which called open(). If this thread has no event loop, then
4234c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * callbacks are delivered to the main application event loop. If there is
4244c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * no main application event loop, callbacks are not delivered.
4254c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <p class="caution">
4264c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * <b>Caution:</b> On some devices, this method may take a long time to
4274c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * complete. It is best to call this method from a worker thread (possibly
4284c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * using {@link android.os.AsyncTask}) to avoid blocking the main
4294c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * application UI thread.
4304c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
4314c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param cameraId The hardware camera to access, between 0 and
4324c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * {@link #getNumberOfCameras()}-1.
433a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @param halVersion The HAL API version this camera device to be opened as.
4344c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @return a new Camera object, connected, locked and ready for use.
435a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
436a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @throws IllegalArgumentException if the {@code halVersion} is invalid
437a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
4384c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @throws RuntimeException if opening the camera fails (for example, if the
4394c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * camera is in use by another process or device policy manager has disabled
4404c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * the camera).
441a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
4424c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
443a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @see #CAMERA_HAL_API_VERSION_1_0
4444c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
4454c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @hide
4464c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
4474c913801141163362dd5bb7c9784c83f69c11054Zhijun He    public static Camera openLegacy(int cameraId, int halVersion) {
448a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
449a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin            throw new IllegalArgumentException("Invalid HAL version " + halVersion);
450a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        }
451a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
4524c913801141163362dd5bb7c9784c83f69c11054Zhijun He        return new Camera(cameraId, halVersion);
4534c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
4544c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4554c913801141163362dd5bb7c9784c83f69c11054Zhijun He    /**
4564c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * Create a legacy camera object.
4574c913801141163362dd5bb7c9784c83f69c11054Zhijun He     *
4584c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param cameraId The hardware camera to access, between 0 and
4594c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * {@link #getNumberOfCameras()}-1.
4604c913801141163362dd5bb7c9784c83f69c11054Zhijun He     * @param halVersion The HAL API version this camera device to be opened as.
4614c913801141163362dd5bb7c9784c83f69c11054Zhijun He     */
4624c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private Camera(int cameraId, int halVersion) {
463a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        int err = cameraInitVersion(cameraId, halVersion);
4644c913801141163362dd5bb7c9784c83f69c11054Zhijun He        if (checkInitErrors(err)) {
4658ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            if (err == -EACCES) {
4668ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Fail to connect to camera service");
4678ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -ENODEV) {
4688ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed");
4698ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -ENOSYS) {
4708ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed because some methods"
4718ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                        + " are not implemented");
4728ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -EOPNOTSUPP) {
4738ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed because the hal"
4748ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                        + " version is not supported by this device");
4758ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -EINVAL) {
4768ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed because the input"
4778ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                        + " arugments are invalid");
4788ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -EBUSY) {
4798ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed because the camera"
4808ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                        + " device was already opened");
4818ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -EUSERS) {
4828ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed because the max"
4838ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                        + " number of camera devices were already opened");
4844c913801141163362dd5bb7c9784c83f69c11054Zhijun He            }
4858ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            // Should never hit this.
4868ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            throw new RuntimeException("Unknown camera error");
4874c913801141163362dd5bb7c9784c83f69c11054Zhijun He        }
4884c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
4894c913801141163362dd5bb7c9784c83f69c11054Zhijun He
490a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private int cameraInitVersion(int cameraId, int halVersion) {
4914c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mShutterCallback = null;
4924c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mRawImageCallback = null;
4934c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mJpegCallback = null;
4944c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mPreviewCallback = null;
4954c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mPostviewCallback = null;
4964c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mUsingPreviewAllocation = false;
4974c913801141163362dd5bb7c9784c83f69c11054Zhijun He        mZoomListener = null;
4984c913801141163362dd5bb7c9784c83f69c11054Zhijun He
4994c913801141163362dd5bb7c9784c83f69c11054Zhijun He        Looper looper;
5004c913801141163362dd5bb7c9784c83f69c11054Zhijun He        if ((looper = Looper.myLooper()) != null) {
5014c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = new EventHandler(this, looper);
5024c913801141163362dd5bb7c9784c83f69c11054Zhijun He        } else if ((looper = Looper.getMainLooper()) != null) {
5034c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = new EventHandler(this, looper);
5044c913801141163362dd5bb7c9784c83f69c11054Zhijun He        } else {
5054c913801141163362dd5bb7c9784c83f69c11054Zhijun He            mEventHandler = null;
5064c913801141163362dd5bb7c9784c83f69c11054Zhijun He        }
5074c913801141163362dd5bb7c9784c83f69c11054Zhijun He
508fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav        return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
509fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav                ActivityThread.currentOpPackageName());
5104c913801141163362dd5bb7c9784c83f69c11054Zhijun He    }
5114c913801141163362dd5bb7c9784c83f69c11054Zhijun He
512a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    private int cameraInitNormal(int cameraId) {
513a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
514a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    }
515a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
516a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    /**
517a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * Connect to the camera service using #connectLegacy
518a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
519a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * <p>
520a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * This acts the same as normal except that it will return
521a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * the detailed error code if open fails instead of
522a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * converting everything into {@code NO_INIT}.</p>
523a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
524a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
525a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
526a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @return a detailed errno error code, or {@code NO_ERROR} on success
527a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     *
528a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     * @hide
529a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin     */
530a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    public int cameraInitUnspecified(int cameraId) {
531a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
532a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    }
533a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin
534a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    /** used by Camera#open, Camera#open(int) */
5357bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li    Camera(int cameraId) {
536a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        int err = cameraInitNormal(cameraId);
537feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        if (checkInitErrors(err)) {
5388ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            if (err == -EACCES) {
5398ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Fail to connect to camera service");
5408ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            } else if (err == -ENODEV) {
5418ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic                throw new RuntimeException("Camera initialization failed");
542feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            }
5438ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            // Should never hit this.
5448ea56f68517ffa42bd5f43ab67f4ebfcfcb0cd23Lazar Trsic            throw new RuntimeException("Unknown camera error");
545feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        }
546503e1fdcd12d2448807d408f00a361bff0857cabjiabin        initAppOps();
547feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    }
548feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
549feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
550feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
551feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
552feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
553feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public static boolean checkInitErrors(int err) {
554feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        return err != NO_ERROR;
555feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    }
556feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk
557feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
558feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
559feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
560feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public static Camera openUninitialized() {
561feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk        return new Camera();
5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5641c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
5651c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * An empty Camera for testing purpose.
5661c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
5671c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    Camera() {
568503e1fdcd12d2448807d408f00a361bff0857cabjiabin        initAppOps();
569503e1fdcd12d2448807d408f00a361bff0857cabjiabin    }
570503e1fdcd12d2448807d408f00a361bff0857cabjiabin
571503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private void initAppOps() {
572503e1fdcd12d2448807d408f00a361bff0857cabjiabin        IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE);
573503e1fdcd12d2448807d408f00a361bff0857cabjiabin        mAppOps = IAppOpsService.Stub.asInterface(b);
574503e1fdcd12d2448807d408f00a361bff0857cabjiabin        // initialize mHasAppOpsPlayAudio
575503e1fdcd12d2448807d408f00a361bff0857cabjiabin        updateAppOpsPlayAudio();
576503e1fdcd12d2448807d408f00a361bff0857cabjiabin        // register a callback to monitor whether the OP_PLAY_AUDIO is still allowed
577503e1fdcd12d2448807d408f00a361bff0857cabjiabin        mAppOpsCallback = new IAppOpsCallbackWrapper(this);
578503e1fdcd12d2448807d408f00a361bff0857cabjiabin        try {
579503e1fdcd12d2448807d408f00a361bff0857cabjiabin            mAppOps.startWatchingMode(AppOpsManager.OP_PLAY_AUDIO,
580503e1fdcd12d2448807d408f00a361bff0857cabjiabin                    ActivityThread.currentPackageName(), mAppOpsCallback);
581503e1fdcd12d2448807d408f00a361bff0857cabjiabin        } catch (RemoteException e) {
582503e1fdcd12d2448807d408f00a361bff0857cabjiabin            Log.e(TAG, "Error registering appOps callback", e);
583503e1fdcd12d2448807d408f00a361bff0857cabjiabin            mHasAppOpsPlayAudio = false;
584503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
585503e1fdcd12d2448807d408f00a361bff0857cabjiabin    }
586503e1fdcd12d2448807d408f00a361bff0857cabjiabin
587503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private void releaseAppOps() {
588503e1fdcd12d2448807d408f00a361bff0857cabjiabin        try {
589503e1fdcd12d2448807d408f00a361bff0857cabjiabin            if (mAppOps != null) {
590503e1fdcd12d2448807d408f00a361bff0857cabjiabin                mAppOps.stopWatchingMode(mAppOpsCallback);
591503e1fdcd12d2448807d408f00a361bff0857cabjiabin            }
592503e1fdcd12d2448807d408f00a361bff0857cabjiabin        } catch (Exception e) {
593503e1fdcd12d2448807d408f00a361bff0857cabjiabin            // nothing to do here, the object is supposed to be released anyway
594503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
5951c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
5961c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
597a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin    @Override
5989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    protected void finalize() {
599e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        release();
6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6024c913801141163362dd5bb7c9784c83f69c11054Zhijun He    private native final int native_setup(Object camera_this, int cameraId, int halVersion,
603788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala                                           String packageName);
604788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala
6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_release();
6069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disconnects and releases the Camera object resources.
610bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
611bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call this as soon as you're done with the Camera object.</p>
6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public final void release() {
6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_release();
6154c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
616503e1fdcd12d2448807d408f00a361bff0857cabjiabin        releaseAppOps();
6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
620bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unlocks the camera to allow another process to access it.
621bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Normally, the camera is locked to the process with an active Camera
622bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * object until {@link #release()} is called.  To allow rapid handoff
623bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * between processes, you can call this method to release the camera
624bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * temporarily for another process to use; once the other process is done
625bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you can call {@link #reconnect()} to reclaim the camera.
626bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
627bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This must be done before calling
62842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
62942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * called after recording starts.
6309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
631bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
633bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be unlocked.
6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
635bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void unlock();
6369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
638bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Re-locks the camera to prevent other processes from accessing it.
639bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera objects are locked by default unless {@link #unlock()} is
640bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called.  Normally {@link #reconnect()} is used instead.
6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
64253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
64342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
64442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
64542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
64642419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     *
647bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
648bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
649bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be re-locked (for
650bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
652ffe1cf251a4f8469695b8acfa37270684dc1b70cWu-cheng Li    public native final void lock();
6539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
655bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Reconnects to the camera service after another process used it.
656bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * After {@link #unlock()} is called, another process may use the
657bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera; when the process is done, you must reconnect to the camera,
658bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * which will re-acquire the lock and allow you to continue using the
659bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera.
6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
66153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
66242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
66342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
66442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
665bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
666bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
667bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
668bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if a connection cannot be re-established (for
669bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
67006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
67106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *     instance.
6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
673bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void reconnect() throws IOException;
6749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
676bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Sets the {@link Surface} to be used for live preview.
677fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
678fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface can be re-set
679fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * without harm.  Setting a preview surface will un-set any preview surface
680fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * texture that was set via {@link #setPreviewTexture}.
6819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
682bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The {@link SurfaceHolder} must already contain a surface when this
683bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method is called.  If you are using {@link android.view.SurfaceView},
684bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you will need to register a {@link SurfaceHolder.Callback} with
685bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
686bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
687bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling setPreviewDisplay() or starting preview.
688bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
689bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method must be called before {@link #startPreview()}.  The
690bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * one exception is that if the preview surface is not set (or set to null)
691bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * before startPreview() is called, then this method may be called once
692bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * with a non-null parameter to set the preview surface.  (This allows
693bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera setup and surface creation to happen in parallel, saving time.)
694bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * The preview surface may not otherwise change while preview is running.
6959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
696bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param holder containing the Surface on which to place the preview,
697bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to remove the preview surface
698bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if the method fails (for example, if the surface
699bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     is unavailable or unsuitable).
70006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
70106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    instance.
7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
704b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        if (holder != null) {
705feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            setPreviewSurface(holder.getSurface());
706b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        } else {
707feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk            setPreviewSurface((Surface)null);
708b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        }
7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
711feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    /**
712feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     * @hide
713feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk     */
714feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk    public native final void setPreviewSurface(Surface surface) throws IOException;
7159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
717fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Sets the {@link SurfaceTexture} to be used for live preview.
718fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
719fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface texture can be
720fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * re-set without harm.  Setting a preview surface texture will un-set any
721fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview surface that was set via {@link #setPreviewDisplay}.
722fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
723fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * <p>This method must be called before {@link #startPreview()}.  The
724fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * one exception is that if the preview surface texture is not set (or set
725fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * to null) before startPreview() is called, then this method may be called
726fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * once with a non-null parameter to set the preview surface.  (This allows
727fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * camera setup and surface creation to happen in parallel, saving time.)
728fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * The preview surface texture may not otherwise change while preview is
729fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * running.
730fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
73132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
732e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * SurfaceTexture set as the preview texture have an unspecified zero point,
733e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * and cannot be directly compared between different cameras or different
734e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * instances of the same camera, or across multiple runs of the same
735e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * program.
736e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     *
737108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
738108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
739108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
740108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
741108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
742108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.graphics.SurfaceTexture
743108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.view.TextureView
744fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @param surfaceTexture the {@link SurfaceTexture} to which the preview
745fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     images are to be sent or null to remove the current preview surface
746fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture
747fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @throws IOException if the method fails (for example, if the surface
748fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture is unavailable or unsuitable).
74906a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
75006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    instance.
751fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     */
752dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
753fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis
754fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis    /**
755bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to deliver copies of preview frames as
756bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * they are displayed.
757bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
758bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallback(Camera.PreviewCallback)
759bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
760bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
761bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startPreview()
762b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
763b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
764b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
766b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PreviewCallback
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
770bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as preview frames are displayed.  This callback is invoked
771341ff13689dfe822b598e626272ac2e80041b482Dan Egnor         * on the event thread {@link #open(int)} was called from.
7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
773951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
774951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
775951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * for the arrangement of the pixel data in the preview callback
776951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * buffers.
777951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
778bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param data the contents of the preview frame in the format defined
779a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *  by {@link android.graphics.ImageFormat}, which can be queried
780df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         *  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
781da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         *  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
7829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             is never called, the default will be the YCbCr_420_SP
7839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             (NV21) format.
784bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param camera the Camera service object.
7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPreviewFrame(byte[] data, Camera camera);
7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
7889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
7899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
790bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts capturing and drawing preview frames to the screen.
791c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * Preview will not actually start until a surface is supplied
792c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * with {@link #setPreviewDisplay(SurfaceHolder)} or
793c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * {@link #setPreviewTexture(SurfaceTexture)}.
794bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
795bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
796bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
797bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
798bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
799bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * will be called when preview data becomes available.
80006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *
80106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if starting preview fails; usually this would be
80206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    because of a hardware or other low-level error, or because release()
80306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    has been called on this Camera instance.
8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final void startPreview();
8069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
8079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
808bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops capturing and drawing preview frames to the surface, and
809bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * resets the camera for a future call to {@link #startPreview()}.
81006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *
81106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if stopping preview fails; usually this would be
81206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    because of a hardware or other low-level error, or because release()
81306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    has been called on this Camera instance.
8149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8154c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopPreview() {
8164c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopPreview();
8174c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
818664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang
819664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mShutterCallback = null;
820664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mRawImageCallback = null;
821664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mPostviewCallback = null;
822664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mJpegCallback = null;
823f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
824f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li            mAutoFocusCallback = null;
825f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        }
8269d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = null;
8274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
8284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
8294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopPreview();
8309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
8319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return current preview state.
8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
8349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * FIXME: Unhide before release
8359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
8369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final boolean previewEnabled();
8389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
8399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
840108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame in addition
841bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to displaying them on the screen.  The callback will be repeatedly called
842bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * for as long as preview is active.  This method can be called at any time,
843108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * even while preview is live.  Any other preview callbacks are
844108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * overridden.</p>
845108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
846108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
847108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
848108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
850bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of each preview frame,
851bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
85206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
85306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *     instance.
854108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
8559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewCallback(PreviewCallback cb) {
8579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = cb;
8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mOneShot = false;
85994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
8607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
8617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
8627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
863a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // Always use one-shot mode. We fake camera preview mode by
864a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // doing one-shot preview continuously.
86594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
8669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
869108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for the next preview frame in
870108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * addition to displaying it on the screen.  After one invocation, the
871108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * callback is cleared. This method can be called any time, even when
872108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview is live.  Any other preview callbacks are overridden.</p>
873108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
874108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
875108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
876108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
878bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the next preview frame,
879bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
88006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
88106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *     instance.
882108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setOneShotPreviewCallback(PreviewCallback cb) {
88594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
88694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = true;
88794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
8887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
8897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
8907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
89194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
89294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    }
89394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
89494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
89594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
89694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
897108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame, using
898108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
899bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * displaying them on the screen.  The callback will be repeatedly called
900108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * for as long as preview is active and buffers are available.  Any other
901108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview callbacks are overridden.</p>
90294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
903bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The purpose of this method is to improve preview efficiency and frame
904bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * rate by allowing preview frame memory reuse.  You must call
905bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #addCallbackBuffer(byte[])} at some point -- before or after
906108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * calling this method -- or no callbacks will received.</p>
90794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
908108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>The buffer queue will be cleared if this method is called with a null
909bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
910108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
911108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * called.</p>
912108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
913108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
914108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
915108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
91694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
917bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the preview frame,
918bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks and clear the buffer queue.
91906a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if release() has been called on this Camera
92006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *     instance.
921bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #addCallbackBuffer(byte[])
922108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
92394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
92494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
92594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
92694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = false;
92794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = true;
9287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
9297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
9307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
93194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, true);
9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
93494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
9353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Adds a pre-allocated buffer to the preview callback buffer queue.
9363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Applications can add one or more buffers to the queue. When a preview
937bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * frame arrives and there is still at least one available buffer, the
938bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * buffer will be used and removed from the queue. Then preview callback is
939bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * invoked with the buffer. If a frame arrives and there is no buffer left,
940bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the frame is discarded. Applications should add buffers back when they
941bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * finish processing the data in them.
942c10275abd6a494c93a025f683dde104a5d4f2793Wu-cheng Li     *
943951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>For formats besides YV12, the size of the buffer is determined by
944951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * multiplying the preview image width, height, and bytes per pixel. The
945951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * width and height can be read from
946951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
947951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
948951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * 8, using the image format from
949951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewFormat()}.
950951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
951951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
952951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * size can be calculated using the equations listed in
953951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#setPreviewFormat}.
95494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
955bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only necessary when
956e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
957bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallback(PreviewCallback)} or
958bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
959e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * are automatically allocated. When a supplied buffer is too small to
960e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * hold the preview frame data, preview callback will return null and
961e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * the buffer will be removed from the buffer queue.
96294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
963951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @param callbackBuffer the buffer to add to the queue. The size of the
964951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *   buffer must match the values described above.
9655b9bcda3a26e9b1f9b1eff28a2be8853d69614f0Wu-cheng Li     * @see #setPreviewCallbackWithBuffer(PreviewCallback)
96694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
967e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addCallbackBuffer(byte[] callbackBuffer)
968e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
969e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
970e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
971e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
972e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    /**
973e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Adds a pre-allocated buffer to the raw image callback buffer queue.
974e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Applications can add one or more buffers to the queue. When a raw image
975e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * frame arrives and there is still at least one available buffer, the
976e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * buffer will be used to hold the raw image data and removed from the
977e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * queue. Then raw image callback is invoked with the buffer. If a raw
978e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * image frame arrives but there is no buffer left, the frame is
979e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * discarded. Applications should add buffers back when they finish
980e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * processing the data in them by calling this method again in order
981e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * to avoid running out of raw image callback buffers.
982e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
983e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>The size of the buffer is determined by multiplying the raw image
984e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * width, height, and bytes per pixel. The width and height can be
985e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
986e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * can be computed from
987e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
988e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
989e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
990e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>This method is only necessary when the PictureCallbck for raw image
991e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * is used while calling {@link #takePicture(Camera.ShutterCallback,
992e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
993e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
99432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Please note that by calling this method, the mode for
99532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * application-managed callback buffers is triggered. If this method has
99632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * never been called, null will be returned by the raw image callback since
99732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * there is no image callback buffer available. Furthermore, When a supplied
99832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * buffer is too small to hold the raw image data, raw image callback will
99932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * return null and the buffer will be removed from the buffer queue.
1000e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
1001e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @param callbackBuffer the buffer to add to the raw image callback buffer
1002e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     queue. The size should be width * height * (bits per pixel) / 8. An
1003e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     null callbackBuffer will be ignored and won't be added to the queue.
1004e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
1005e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @see #takePicture(Camera.ShutterCallback,
1006e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
1007e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
1008e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@hide}
1009e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     */
1010e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
1011e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
1012e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
1013e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
1014e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1015e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
1016e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
1017e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
1018e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
1019e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType != CAMERA_MSG_RAW_IMAGE) {
1020e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            throw new IllegalArgumentException(
1021e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                            "Unsupported message type: " + msgType);
1022e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1023e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1024e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, msgType);
1025e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
1026e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1027e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void _addCallbackBuffer(
1028e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                                byte[] callbackBuffer, int msgType);
10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
10317005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Create a {@link android.renderscript RenderScript}
10327005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation Allocation} to use as a
10337005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * destination of preview callback frames. Use
10347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
10357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the created Allocation as a destination for camera preview frames.</p>
10367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>The Allocation will be created with a YUV type, and its contents must
10387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
10397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * accessor methods. Its size will be based on the current
10407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#getPreviewSize preview size} configured for this
10417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * camera.</p>
10427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param rs the RenderScript context for this Allocation.
10447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param usage additional usage flags to set for the Allocation. The usage
10457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
10467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   be set on the created Allocation, but additional flags may be provided
10477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   here.
10487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @return a new YUV-type Allocation with dimensions equal to the current
10497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview size.
10507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws RSIllegalArgumentException if the usage flags are not compatible
10517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   with an YUV Allocation.
10527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackAllocation
10537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
10547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
10557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final Allocation createPreviewAllocation(RenderScript rs, int usage)
10567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws RSIllegalArgumentException {
10577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Parameters p = getParameters();
10587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Size previewSize = p.getPreviewSize();
10597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Type.Builder yuvBuilder = new Type.Builder(rs,
10607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                Element.createPixel(rs,
10617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataType.UNSIGNED_8,
10627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataKind.PIXEL_YUV));
10637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // Use YV12 for wide compatibility. Changing this requires also
10647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // adjusting camera service's format selection.
10657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setYuvFormat(ImageFormat.YV12);
10667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setX(previewSize.width);
10677005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setY(previewSize.height);
10687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
10697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
10707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                usage | Allocation.USAGE_IO_INPUT);
10717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
10727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        return a;
10737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
10747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
10757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
10767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Set an {@link android.renderscript.Allocation Allocation} as the
10777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * target of preview callback data. Use this method for efficient processing
10787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * of camera preview data with RenderScript. The Allocation must be created
10797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * with the {@link #createPreviewAllocation createPreviewAllocation }
10807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * method.</p>
10817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Setting a preview allocation will disable any active preview callbacks
10837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * set by {@link #setPreviewCallback setPreviewCallback} or
10847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
10857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * vice versa. Using a preview allocation still requires an active standard
10867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview target to be set, either with
10877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewTexture setPreviewTexture} or
10887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewDisplay setPreviewDisplay}.</p>
10897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To be notified when new frames are available to the Allocation, use
10917005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
10927005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * update the frame currently accessible from the Allocation to the latest
10937005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview frame, call
10947005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
10957005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10967005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To disable preview into the Allocation, call this method with a
10977005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@code null} parameter.</p>
10987005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
10997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Once a preview allocation is set, the preview size set by
11007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
11017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * you wish to change the preview size, first remove the preview allocation
11027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * by calling {@code setPreviewCallbackAllocation(null)}, then change the
11037005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview size, create a new preview Allocation with
11047005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
11057005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the new preview callback allocation target.</p>
11067005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
11077005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
11087005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
11097005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
11107005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
11117005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param previewAllocation the allocation to use as destination for preview
11127005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IOException if configuring the camera to use the Allocation for
11137005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview fails.
11147005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IllegalArgumentException if the Allocation's dimensions or other
11157005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   parameters don't meet the requirements.
11167005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #createPreviewAllocation
11177005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallback
11187005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackWithBuffer
11197005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
11207005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
11217005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final void setPreviewCallbackAllocation(Allocation previewAllocation)
11227005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws IOException {
11237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Surface previewSurface = null;
11247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (previewAllocation != null) {
11257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Parameters p = getParameters();
11267005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Size previewSize = p.getPreviewSize();
11277005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewSize.width != previewAllocation.getType().getX() ||
11287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height != previewAllocation.getType().getY()) {
11297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
11307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation dimensions don't match preview dimensions: " +
11317005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is " +
11327005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getX() +
11337005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ", " +
11347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getY() +
11357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ". Preview is " + previewSize.width + ", " +
11367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height);
11377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
11387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if ((previewAllocation.getUsage() &
11397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                             Allocation.USAGE_IO_INPUT) == 0) {
11407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
11417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation usage does not include USAGE_IO_INPUT");
11427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
11437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewAllocation.getType().getElement().getDataKind() !=
11447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     Element.DataKind.PIXEL_YUV) {
11457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
11467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is not of a YUV type");
11477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
11487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             previewSurface = previewAllocation.getSurface();
11497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = true;
11507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         } else {
11517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = false;
11527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         }
11537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         setPreviewCallbackSurface(previewSurface);
11547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
11557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
11567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private native final void setPreviewCallbackSurface(Surface s);
11577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
11589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class EventHandler extends Handler
11599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
1160a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        private final Camera mCamera;
11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public EventHandler(Camera c, Looper looper) {
11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            super(looper);
11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mCamera = c;
11659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
11669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        @Override
11689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void handleMessage(Message msg) {
11699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(msg.what) {
1170c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_SHUTTER:
11719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mShutterCallback != null) {
11729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mShutterCallback.onShutter();
11739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
11749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
1175c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks
1176c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_RAW_IMAGE:
1177e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mRawImageCallback != null) {
11789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
1179e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
11809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1182c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_COMPRESSED_IMAGE:
1183e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mJpegCallback != null) {
11849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
1185e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
11869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
11879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
1188c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_PREVIEW_FRAME:
1189ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                PreviewCallback pCb = mPreviewCallback;
1190ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                if (pCb != null) {
11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    if (mOneShot) {
1192a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Clear the callback variable before the callback
1193a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // in case the app calls setPreviewCallback from
1194a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the callback function
11959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        mPreviewCallback = null;
119694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                    } else if (!mWithBuffer) {
1197a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // We're faking the camera preview mode to prevent
1198a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the app from being flooded with preview frames.
1199a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Set to oneshot mode again.
120094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                        setHasPreviewCallback(true, false);
12019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    }
1202ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                    pCb.onPreviewFrame((byte[])msg.obj, mCamera);
12039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
12049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
12059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1206e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_POSTVIEW_FRAME:
1207e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mPostviewCallback != null) {
1208e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                    mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
1209e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
1210e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
1211e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1212c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_FOCUS:
1213f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                AutoFocusCallback cb = null;
1214f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                synchronized (mAutoFocusCallbackLock) {
1215f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb = mAutoFocusCallback;
1216f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                }
1217f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                if (cb != null) {
1218f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    boolean success = msg.arg1 == 0 ? false : true;
1219f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb.onAutoFocus(success, mCamera);
1220e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
1221e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
1222e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1223e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_ZOOM:
12243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                if (mZoomListener != null) {
12253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                    mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
1226e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
12279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
12289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1229bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li            case CAMERA_MSG_PREVIEW_METADATA:
12304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                if (mFaceListener != null) {
1231f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li                    mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
12324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                }
12334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                return;
12344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1235c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_ERROR :
12369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Error " + msg.arg1);
1237e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mErrorCallback != null) {
12389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mErrorCallback.onError(msg.arg1, mCamera);
1239e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
12409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
12419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12429d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li            case CAMERA_MSG_FOCUS_MOVE:
12439d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                if (mAutoFocusMoveCallback != null) {
12449d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                    mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
12459d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                }
12469d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                return;
12479d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            default:
12499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Unknown message type " + msg.what);
12509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
12519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
12529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
12539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static void postEventFromNative(Object camera_ref,
12569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                            int what, int arg1, int arg2, Object obj)
12579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
12589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Camera c = (Camera)((WeakReference)camera_ref).get();
12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c == null)
12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c.mEventHandler != null) {
12639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
12649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            c.mEventHandler.sendMessage(m);
12659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
12669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
12689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1269bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to notify on completion of camera auto focus.
1270bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
12717478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * <p>Devices that do not support auto-focus will receive a "fake"
12727478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * callback to this interface. If your application needs auto-focus and
1273df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * should not be installed on devices <em>without</em> auto-focus, you must
1274df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * declare that your app uses the
12757478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * {@code android.hardware.camera.autofocus} feature, in the
1276df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1277df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1278bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1279bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(AutoFocusCallback)
1280b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1281b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
12829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1283b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
12849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface AutoFocusCallback
12859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
12869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
128769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * Called when the camera auto focus completes.  If the camera
128869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * does not support auto-focus and autoFocus is called,
128969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * onAutoFocus will be called immediately with a fake value of
129069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <code>success</code> set to <code>true</code>.
12919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
1292b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * The auto-focus routine does not lock auto-exposure and auto-white
1293b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * balance after it completes.
129483d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         *
12959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param success true if focus was successful, false if otherwise
12969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
129783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
129883d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
12999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
13009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onAutoFocus(boolean success, Camera camera);
130153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li    }
13029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1304bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts camera auto-focus and registers a callback function to run when
1305bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the camera is focused.  This method is only valid when preview is active
1306bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * (between {@link #startPreview()} and before {@link #stopPreview()}).
1307bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1308bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callers should check
1309bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1310bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this method should be called. If the camera does not support auto-focus,
1311bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
131236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li     * callback will be called immediately.
1313bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1314da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main     * <p>If your application should not be installed
13157478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * on devices without auto-focus, you must declare that your application
13167478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * uses auto-focus with the
1317df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1318df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1319bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1320068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * <p>If the current flash mode is not
1321068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
1322bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * fired during auto-focus, depending on the driver and camera hardware.<p>
13237478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     *
132453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
1325b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1326b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * do not change during and after autofocus. But auto-focus routine may stop
1327b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * auto-exposure and auto-white balance transiently during focusing.
132883d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     *
132953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Stopping preview with {@link #stopPreview()}, or triggering still
133053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * image capture with {@link #takePicture(Camera.ShutterCallback,
133153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
133253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * the focus position. Applications must call cancelAutoFocus to reset the
133353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * focus.</p>
133453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1335108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If autofocus is successful, consider using
1336108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * {@link android.media.MediaActionSound} to properly play back an autofocus
1337108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * success sound to the user.</p>
1338108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
13399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param cb the callback to run
134006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if starting autofocus fails; usually this would
134106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    be because of a hardware or other low-level error, or because
134206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    release() has been called on this Camera instance.
1343bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #cancelAutoFocus()
134483d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
134583d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
1346108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
13479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
13489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void autoFocus(AutoFocusCallback cb)
13499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
1350f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1351248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = cb;
1352248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1353f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_autoFocus();
13549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
13559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_autoFocus();
13569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
13579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1358bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Cancels any auto-focus function in progress.
1359bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Whether or not auto-focus is currently in progress,
1360bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this function will return the focus position to the default.
1361244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     * If the camera does not support auto-focus, this is a no-op.
1362bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
136306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if canceling autofocus fails; usually this would
136406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    be because of a hardware or other low-level error, or because
136506a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    release() has been called on this Camera instance.
1366bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(Camera.AutoFocusCallback)
1367244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     */
1368244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    public final void cancelAutoFocus()
1369244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    {
1370f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1371248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = null;
1372248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1373f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_cancelAutoFocus();
1374f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // CAMERA_MSG_FOCUS should be removed here because the following
1375f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // scenario can happen:
1376f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - An application uses the same thread for autoFocus, cancelAutoFocus
1377f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   and looper thread.
1378f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application calls autoFocus.
1379f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1380f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   Before event handler's handleMessage() is invoked, the application
1381f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   calls cancelAutoFocus and autoFocus.
1382f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1383f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   has been completed. But in fact it is not.
1384f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //
1385f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // As documented in the beginning of the file, apps should not use
1386f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // multiple threads to call autoFocus and cancelAutoFocus at the same
1387f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1388f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // message after native_cancelAutoFocus is called.
1389f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
1390244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    }
1391244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    private native final void native_cancelAutoFocus();
1392244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang
1393244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    /**
13949d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Callback interface used to notify on auto focus start and stop.
13959d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
13966574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * <p>This is only supported in continuous autofocus modes -- {@link
13976574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
13986574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
13996574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * autofocus animation based on this.</p>
1400b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1401b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1402b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
14039d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
1404b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
14059d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public interface AutoFocusMoveCallback
14069d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    {
14079d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        /**
14089d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * Called when the camera auto focus starts or stops.
14099d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         *
14109d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * @param start true if focus starts to move, false if focus stops to move
14116574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li         * @param camera the Camera service object
14129d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         */
14139d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        void onAutoFocusMoving(boolean start, Camera camera);
14149d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
14159d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
14169d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
14179d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Sets camera auto-focus move callback.
14189d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
14199d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * @param cb the callback to run
142006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if enabling the focus move callback fails;
142106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    usually this would be because of a hardware or other low-level error,
142206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    or because release() has been called on this Camera instance.
14239d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
14249d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
14259d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = cb;
14269d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
14279d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
14289d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
14299d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private native void enableFocusMoveCallback(int enable);
14309d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
14319d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
1432bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to signal the moment of actual image capture.
1433bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1434bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
1435b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1436b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1437b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
14389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1439b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
14409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ShutterCallback
14419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
14429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1443bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as near as possible to the moment when a photo is captured
1444bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * from the sensor.  This is a good opportunity to play a shutter sound
1445bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * or give other feedback of camera operation.  This may be some time
1446bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * after the photo was triggered, but some time before the actual data
1447bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * is available.
14489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
14499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onShutter();
14509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
14519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
14529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1453bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to supply image data from a photo capture.
1454bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1455bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
1456b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1457b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1458b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
14599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1460b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
14619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PictureCallback {
14629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1463bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when image data is available after a picture is taken.
1464bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * The format of the data depends on the context of the callback
1465bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * and {@link Camera.Parameters} settings.
14669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
14679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param data   a byte array of the picture data
14689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera the Camera service object
14699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
14709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPictureTaken(byte[] data, Camera camera);
14719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
14729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
14739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
147406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>.
14759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
1476bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
14779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
14789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
14799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            PictureCallback jpeg) {
1480e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        takePicture(shutter, raw, null, jpeg);
1481e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
1482e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void native_takePicture(int msgType);
1483e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1484e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
14859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * Triggers an asynchronous image capture. The camera service will initiate
14869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * a series of callbacks to the application as the image capture progresses.
14879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The shutter callback occurs after the image is captured. This can be used
14889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * to trigger a sound to let the user know that image has been captured. The
14899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * raw callback occurs when the raw image data is available (NOTE: the data
1490e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * will be null if there is no raw image callback buffer available or the
1491e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * raw image callback buffer is not large enough to hold the raw image).
14929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The postview callback occurs when a scaled, fully processed postview
14939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * image is available (NOTE: not all hardware supports this). The jpeg
14949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * callback occurs when the compressed image is available. If the
14959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * application does not need a particular callback, a null can be passed
14969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * instead of a callback method.
1497e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     *
1498bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only valid when preview is active (after
1499bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #startPreview()}).  Preview will be stopped after the image is
1500bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * taken; callers must call {@link #startPreview()} again if they want to
150142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * re-start preview or take more pictures. This should not be called between
150242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()} and
150342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#stop()}.
150440057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1505bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>After calling this method, you must not call {@link #startPreview()}
1506bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * or take another picture until the JPEG callback has returned.
150740057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1508bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param shutter   the callback for image capture moment, or null
1509bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param raw       the callback for raw (uncompressed) image data, or null
1510e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     * @param postview  callback with postview image data, may be null
1511bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param jpeg      the callback for JPEG image data, or null
151206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if starting picture capture fails; usually this
151306a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    would be because of a hardware or other low-level error, or because
151406a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    release() has been called on this Camera instance.
1515e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
1516e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1517e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            PictureCallback postview, PictureCallback jpeg) {
15189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = shutter;
15199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = raw;
1520e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = postview;
15219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = jpeg;
1522e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1523e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // If callback is not set, do not send me callbacks.
1524e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        int msgType = 0;
1525e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mShutterCallback != null) {
1526e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_SHUTTER;
1527e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1528e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mRawImageCallback != null) {
1529e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_RAW_IMAGE;
1530e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1531e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mPostviewCallback != null) {
1532e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1533e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1534e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mJpegCallback != null) {
1535e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1536e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1537e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1538e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        native_takePicture(msgType);
1539e9c6c9ccfde7a642a4c0554e2d066f3dbbea98ceWu-cheng Li        mFaceDetectionRunning = false;
15409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
15419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1542e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
1543bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Zooms to the requested value smoothly. The driver will notify {@link
15443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
15453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * the time. For example, suppose the current zoom is 0 and startSmoothZoom
1546bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with value 3. The
1547bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1548bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method will be called three times with zoom values 1, 2, and 3.
1549bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1550bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications should not call startSmoothZoom again or change the zoom
1551bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * value before zoom stops. If the supplied zoom value equals to the current
1552bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * zoom value, no zoom callback will be generated. This method is supported
1553bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1554bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * returns true.
155536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *
155636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * @param value zoom value. The valid range is 0 to {@link
155736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *              android.hardware.Camera.Parameters#getMaxZoom}.
15580ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws IllegalArgumentException if the zoom value is invalid.
15590ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
1560bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
156136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
156236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void startSmoothZoom(int value);
156336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
156436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
1565bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops the smooth zoom. Applications should wait for the {@link
15663f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} to know when the zoom is actually stopped. This
15673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * method is supported if {@link
15688cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
15690ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     *
15700ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
157136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
157236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void stopSmoothZoom();
157336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
157436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
15752fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * Set the clockwise rotation of preview display in degrees. This affects
15762fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * the preview frames and the picture displayed after snapshot. This method
15772fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * is useful for portrait mode applications. Note that preview display of
1578b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * front-facing cameras is flipped horizontally before the rotation, that
1579b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * is, the image is reflected along the central vertical axis of the camera
1580b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * sensor. So the users can see themselves as looking into a mirror.
1581d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
158269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>This does not affect the order of byte array passed in {@link
15832fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
15842fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * method is not allowed to be called during preview.
1585d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
158669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>If you want to make the camera image show in the same orientation as
158769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * the display, you can use the following code.
1588b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * <pre>
1589724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * public static void setCameraDisplayOrientation(Activity activity,
1590724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         int cameraId, android.hardware.Camera camera) {
1591724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.CameraInfo info =
1592724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             new android.hardware.Camera.CameraInfo();
1593724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.getCameraInfo(cameraId, info);
1594724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int rotation = activity.getWindowManager().getDefaultDisplay()
1595724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             .getRotation();
1596724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int degrees = 0;
1597724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     switch (rotation) {
1598724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_0: degrees = 0; break;
1599724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_90: degrees = 90; break;
1600724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_180: degrees = 180; break;
1601724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_270: degrees = 270; break;
1602724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     }
1603b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     *
16042fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     int result;
16052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
16062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation + degrees) % 360;
16072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (360 - result) % 360;  // compensate the mirror
16082fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     } else {  // back-facing
16092fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation - degrees + 360) % 360;
16102fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     }
1611724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     camera.setDisplayOrientation(result);
1612724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * }
1613b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * </pre>
1614d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1615d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * <p>Starting from API level 14, this method can be called when preview is
1616d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * active.
1617d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
16186c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in
16196c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * API level 24, the default orientation will be such that applications in forced-landscape mode
16206c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * will have correct preview orientation, which may be either a default of 0 or
16216c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * 180. Applications that operate in portrait mode or allow for changing orientation must still
16226c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * call this method after each orientation change to ensure correct preview display in all
16236c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     * cases.</p>
16246c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     *
1625d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     * @param degrees the angle that the picture will be rotated clockwise.
16266c91e2c31b514bcfd838c75b4c74412e7288415dEino-Ville Talvala     *                Valid values are 0, 90, 180, and 270.
162706a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if setting orientation fails; usually this would
162806a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    be because of a hardware or other low-level error, or because
162906a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    release() has been called on this Camera instance.
16302fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * @see #setPreviewDisplay(SurfaceHolder)
1631d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     */
1632d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    public native final void setDisplayOrientation(int degrees);
1633d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang
1634d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    /**
1635487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Enable or disable the default shutter sound when taking a picture.</p>
163669fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1637487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>By default, the camera plays the system-defined camera shutter sound
1638487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * when {@link #takePicture} is called. Using this method, the shutter sound
1639487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be disabled. It is strongly recommended that an alternative shutter
1640487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is played in the {@link ShutterCallback} when the system shutter
1641487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is disabled.</p>
164269fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1643487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Note that devices may not always allow disabling the camera shutter
1644487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound. If the shutter sound state cannot be set to the desired value,
1645487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * this method will return false. {@link CameraInfo#canDisableShutterSound}
1646487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be used to determine whether the device will allow the shutter sound
1647487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * to be disabled.</p>
164869fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
164969fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @param enabled whether the camera should play the system shutter sound
165069fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *                when {@link #takePicture takePicture} is called.
1651487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @return {@code true} if the shutter sound state was successfully
1652487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code false} if the shutter sound state could not be
1653487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code true} is also returned if shutter sound playback
1654487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         is already set to the requested state.
165506a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if the call fails; usually this would be because
165606a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    of a hardware or other low-level error, or because release() has been
165706a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    called on this Camera instance.
165869fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see #takePicture
1659487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @see CameraInfo#canDisableShutterSound
166069fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see ShutterCallback
166169fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     */
16624f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public final boolean enableShutterSound(boolean enabled) {
1663e059e45b053454deb1044123a5a65ba725fb952cjiabin        boolean canDisableShutterSound = true;
1664e059e45b053454deb1044123a5a65ba725fb952cjiabin        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1665e059e45b053454deb1044123a5a65ba725fb952cjiabin        IAudioService audioService = IAudioService.Stub.asInterface(b);
1666e059e45b053454deb1044123a5a65ba725fb952cjiabin        try {
1667e059e45b053454deb1044123a5a65ba725fb952cjiabin            if (audioService.isCameraSoundForced()) {
1668e059e45b053454deb1044123a5a65ba725fb952cjiabin                canDisableShutterSound = false;
16694f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
1670e059e45b053454deb1044123a5a65ba725fb952cjiabin        } catch (RemoteException e) {
1671e059e45b053454deb1044123a5a65ba725fb952cjiabin            Log.e(TAG, "Audio service is unavailable for queries");
1672e059e45b053454deb1044123a5a65ba725fb952cjiabin        }
1673e059e45b053454deb1044123a5a65ba725fb952cjiabin        if (!enabled && !canDisableShutterSound) {
1674e059e45b053454deb1044123a5a65ba725fb952cjiabin            return false;
16754f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
1676503e1fdcd12d2448807d408f00a361bff0857cabjiabin        synchronized (mShutterSoundLock) {
1677e059e45b053454deb1044123a5a65ba725fb952cjiabin            mShutterSoundEnabledFromApp = enabled;
1678e059e45b053454deb1044123a5a65ba725fb952cjiabin            // Return the result of _enableShutterSound(enabled) in all cases.
1679e059e45b053454deb1044123a5a65ba725fb952cjiabin            // If the shutter sound can be disabled, disable it when the device is in DnD mode.
1680503e1fdcd12d2448807d408f00a361bff0857cabjiabin            boolean ret = _enableShutterSound(enabled);
1681e059e45b053454deb1044123a5a65ba725fb952cjiabin            if (enabled && !mHasAppOpsPlayAudio) {
1682e059e45b053454deb1044123a5a65ba725fb952cjiabin                Log.i(TAG, "Shutter sound is not allowed by AppOpsManager");
1683e059e45b053454deb1044123a5a65ba725fb952cjiabin                if (canDisableShutterSound) {
1684e059e45b053454deb1044123a5a65ba725fb952cjiabin                    _enableShutterSound(false);
1685e059e45b053454deb1044123a5a65ba725fb952cjiabin                }
1686503e1fdcd12d2448807d408f00a361bff0857cabjiabin            }
1687503e1fdcd12d2448807d408f00a361bff0857cabjiabin            return ret;
1688503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
16894f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
16904f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala
16916653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    /**
16926653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * Disable the shutter sound unconditionally.
16936653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
16946653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * <p>
16956653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * This is only guaranteed to work for legacy cameras
16966653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on
16976653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * a regular camera will force a conditional check in the camera service.
16986653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * </p>
16996653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
17006653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * @return {@code true} if the shutter sound state was successfully
17016653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         changed. {@code false} if the shutter sound state could not be
17026653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         changed. {@code true} is also returned if shutter sound playback
17036653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *         is already set to the requested state.
17046653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     *
17056653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     * @hide
17066653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin     */
17076653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    public final boolean disableShutterSound() {
17086653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin        return _enableShutterSound(/*enabled*/false);
17096653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin    }
17106653362f6b5c5854bd88244bcecad72d11bf9404Igor Murashkin
17114f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native final boolean _enableShutterSound(boolean enabled);
171269fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala
1713503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private static class IAppOpsCallbackWrapper extends IAppOpsCallback.Stub {
1714503e1fdcd12d2448807d408f00a361bff0857cabjiabin        private final WeakReference<Camera> mWeakCamera;
1715503e1fdcd12d2448807d408f00a361bff0857cabjiabin
1716503e1fdcd12d2448807d408f00a361bff0857cabjiabin        IAppOpsCallbackWrapper(Camera camera) {
1717503e1fdcd12d2448807d408f00a361bff0857cabjiabin            mWeakCamera = new WeakReference<Camera>(camera);
1718503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
1719503e1fdcd12d2448807d408f00a361bff0857cabjiabin
1720503e1fdcd12d2448807d408f00a361bff0857cabjiabin        @Override
1721503e1fdcd12d2448807d408f00a361bff0857cabjiabin        public void opChanged(int op, int uid, String packageName) {
1722503e1fdcd12d2448807d408f00a361bff0857cabjiabin            if (op == AppOpsManager.OP_PLAY_AUDIO) {
1723503e1fdcd12d2448807d408f00a361bff0857cabjiabin                final Camera camera = mWeakCamera.get();
1724503e1fdcd12d2448807d408f00a361bff0857cabjiabin                if (camera != null) {
1725503e1fdcd12d2448807d408f00a361bff0857cabjiabin                    camera.updateAppOpsPlayAudio();
1726503e1fdcd12d2448807d408f00a361bff0857cabjiabin                }
1727503e1fdcd12d2448807d408f00a361bff0857cabjiabin            }
1728503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
1729503e1fdcd12d2448807d408f00a361bff0857cabjiabin    }
1730503e1fdcd12d2448807d408f00a361bff0857cabjiabin
1731503e1fdcd12d2448807d408f00a361bff0857cabjiabin    private void updateAppOpsPlayAudio() {
1732503e1fdcd12d2448807d408f00a361bff0857cabjiabin        synchronized (mShutterSoundLock) {
1733503e1fdcd12d2448807d408f00a361bff0857cabjiabin            boolean oldHasAppOpsPlayAudio = mHasAppOpsPlayAudio;
1734503e1fdcd12d2448807d408f00a361bff0857cabjiabin            try {
1735503e1fdcd12d2448807d408f00a361bff0857cabjiabin                int mode = AppOpsManager.MODE_IGNORED;
1736503e1fdcd12d2448807d408f00a361bff0857cabjiabin                if (mAppOps != null) {
1737503e1fdcd12d2448807d408f00a361bff0857cabjiabin                    mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO,
1738503e1fdcd12d2448807d408f00a361bff0857cabjiabin                            AudioAttributes.USAGE_ASSISTANCE_SONIFICATION,
1739503e1fdcd12d2448807d408f00a361bff0857cabjiabin                            Process.myUid(), ActivityThread.currentPackageName());
1740503e1fdcd12d2448807d408f00a361bff0857cabjiabin                }
1741503e1fdcd12d2448807d408f00a361bff0857cabjiabin                mHasAppOpsPlayAudio = mode == AppOpsManager.MODE_ALLOWED;
1742503e1fdcd12d2448807d408f00a361bff0857cabjiabin            } catch (RemoteException e) {
1743503e1fdcd12d2448807d408f00a361bff0857cabjiabin                Log.e(TAG, "AppOpsService check audio operation failed");
1744503e1fdcd12d2448807d408f00a361bff0857cabjiabin                mHasAppOpsPlayAudio = false;
1745503e1fdcd12d2448807d408f00a361bff0857cabjiabin            }
1746503e1fdcd12d2448807d408f00a361bff0857cabjiabin            if (oldHasAppOpsPlayAudio != mHasAppOpsPlayAudio) {
1747503e1fdcd12d2448807d408f00a361bff0857cabjiabin                if (!mHasAppOpsPlayAudio) {
1748e059e45b053454deb1044123a5a65ba725fb952cjiabin                    IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
1749e059e45b053454deb1044123a5a65ba725fb952cjiabin                    IAudioService audioService = IAudioService.Stub.asInterface(b);
1750e059e45b053454deb1044123a5a65ba725fb952cjiabin                    try {
1751e059e45b053454deb1044123a5a65ba725fb952cjiabin                        if (audioService.isCameraSoundForced()) {
1752e059e45b053454deb1044123a5a65ba725fb952cjiabin                            return;
1753e059e45b053454deb1044123a5a65ba725fb952cjiabin                        }
1754e059e45b053454deb1044123a5a65ba725fb952cjiabin                    } catch (RemoteException e) {
1755e059e45b053454deb1044123a5a65ba725fb952cjiabin                        Log.e(TAG, "Audio service is unavailable for queries");
1756e059e45b053454deb1044123a5a65ba725fb952cjiabin                    }
1757503e1fdcd12d2448807d408f00a361bff0857cabjiabin                    _enableShutterSound(false);
1758503e1fdcd12d2448807d408f00a361bff0857cabjiabin                } else {
1759e059e45b053454deb1044123a5a65ba725fb952cjiabin                    enableShutterSound(mShutterSoundEnabledFromApp);
1760503e1fdcd12d2448807d408f00a361bff0857cabjiabin                }
1761503e1fdcd12d2448807d408f00a361bff0857cabjiabin            }
1762503e1fdcd12d2448807d408f00a361bff0857cabjiabin        }
1763503e1fdcd12d2448807d408f00a361bff0857cabjiabin    }
1764503e1fdcd12d2448807d408f00a361bff0857cabjiabin
176569fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala    /**
1766bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for zoom changes during a smooth zoom operation.
1767bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1768bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
1769bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startSmoothZoom(int)
1770b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
1771b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1772b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
1773e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
1774b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
17753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public interface OnZoomChangeListener
1776e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
1777e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        /**
1778bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when the zoom value has changed during a smooth zoom.
177936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
178036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param zoomValue the current zoom value. In smooth zoom mode, camera
17813f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *                  calls this for every new zoom value.
178236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param stopped whether smooth zoom is stopped. If the value is true,
178336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *                this is the last zoom update for the application.
1784e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         * @param camera  the Camera service object
1785e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         */
17863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        void onZoomChange(int zoomValue, boolean stopped, Camera camera);
1787e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    };
1788e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1789e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
17903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Registers a listener to be notified when the zoom value is updated by the
179136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * camera driver during smooth zoom.
17928cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     *
17933f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * @param listener the listener to notify
17948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * @see #startSmoothZoom(int)
1795e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
17963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public final void setZoomChangeListener(OnZoomChangeListener listener)
1797e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
17983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = listener;
1799e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
18009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18014c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
18024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Callback interface for face detected in the preview frame.
18034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1804b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1805b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
18064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1807b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
18084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public interface FaceDetectionListener
18094c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
18104c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
18114c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Notify the listener of the detected faces in the preview frame.
18124c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
181353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @param faces The detected faces in a list
1814464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @param camera  The {@link Camera} service object
18154c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1816f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li        void onFaceDetection(Face[] faces, Camera camera);
18174c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
18184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
18194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1820c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Registers a listener to be notified about the faces detected in the
18214c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * preview frame.
18224c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
18234c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @param listener the listener to notify
1824c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see #startFaceDetection()
18254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
18264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void setFaceDetectionListener(FaceDetectionListener listener)
18274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
18284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceListener = listener;
18294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
18304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
18314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1832c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Starts the face detection. This should be called after preview is started.
18334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * The camera will notify {@link FaceDetectionListener} of the detected
18344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * faces in the preview frame. The detected faces may be the same as the
18354c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * previous ones. Applications should call {@link #stopFaceDetection} to
18364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * stop the face detection. This method is supported if {@link
1837c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
18384c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * If the face detection has started, apps should not call this again.
18394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
18408c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
18414c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
18428c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * have no effect. The camera uses the detected faces to do auto-white balance,
18438c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * auto exposure, and autofocus.
18448c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
18458c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
18468c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * will stop sending face callbacks. The last face callback indicates the
18478c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * areas used to do autofocus. After focus completes, face detection will
18488c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * resume sending face callbacks. If the apps call {@link
18498c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * #cancelAutoFocus()}, the face callbacks will also resume.</p>
18508c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
18518c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
18528c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
18538c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * preview with {@link #startPreview()}, the apps should call this method
18548c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * again to resume face detection.</p>
18554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1856c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @throws IllegalArgumentException if the face detection is unsupported.
18574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @throws RuntimeException if the method fails or the face detection is
18584c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *         already running.
18594c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see FaceDetectionListener
18604c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see #stopFaceDetection()
1861c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see Parameters#getMaxNumDetectedFaces()
18624c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1863c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    public final void startFaceDetection() {
18644c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        if (mFaceDetectionRunning) {
18654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li            throw new RuntimeException("Face detection is already running");
18664c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
1867c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        _startFaceDetection(CAMERA_FACE_DETECTION_HW);
18684c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = true;
18694c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
18704c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
18714c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1872c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Stops the face detection.
18734c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1874464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see #startFaceDetection()
18754c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
18764c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopFaceDetection() {
18774c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopFaceDetection();
18784c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
18794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
18804c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
18814c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _startFaceDetection(int type);
18824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopFaceDetection();
18834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
18844c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1885464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * Information about a face identified through camera face detection.
188653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1887464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1888464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * list of face objects for use in focusing and metering.</p>
18894c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1890464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see FaceDetectionListener
1891b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
1892b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
18934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1894b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
1895f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li    public static class Face {
1896c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        /**
1897c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * Create an empty face.
1898c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         */
1899bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Face() {
1900bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        }
1901bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li
19024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
19034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Bounds of the face. (-1000, -1000) represents the top-left of the
19044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * camera field of view, and (1000, 1000) represents the bottom-right of
1905c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * the field of view. For example, suppose the size of the viewfinder UI
1906c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
19078c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
19088c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * guaranteed left < right and top < bottom. The coordinates can be
19098c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * smaller than -1000 or bigger than 1000. But at least one vertex will
19108c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * be within (-1000, -1000) and (1000, 1000).
1911f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         *
1912f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * <p>The direction is relative to the sensor orientation, that is, what
1913f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * the sensor sees. The direction is not affected by the rotation or
19148c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
19158c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * rectangle does not provide any information about face orientation.</p>
19168c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         *
19178c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <p>Here is the matrix to convert driver coordinates to View coordinates
19188c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * in pixels.</p>
19198c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <pre>
19208c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * Matrix matrix = new Matrix();
19218c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
19228c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Need mirror for front camera.
19238c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
19248c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.setScale(mirror ? -1 : 1, 1);
19258c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // This is the value for android.hardware.Camera.setDisplayOrientation.
19268c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postRotate(displayOrientation);
19278c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
19288c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // UI coordinates range from (0, 0) to (width, height).
19298c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
19308c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
19318c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * </pre>
19324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1933464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
19344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1935bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Rect rect;
19364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
19374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
19388df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>The confidence level for the detection of the face. The range is 1 to
19398df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * 100. 100 is the highest confidence.</p>
19408df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         *
19418df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>Depending on the device, even very low-confidence faces may be
19428df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * listed, so applications should filter out faces with low confidence,
19438df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * depending on the use case. For a typical point-and-shoot camera
19448df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * application that wishes to display rectangles around detected faces,
19458df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * filtering out faces with confidence less than 50 is recommended.</p>
19464c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1947464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
19484c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1949bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public int score;
1950d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1951d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1952d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * An unique id per face while the face is visible to the tracker. If
1953d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the face leaves the field-of-view and comes back, it will get a new
1954d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * id. This is an optional field, may not be supported on all devices.
1955d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * If not supported, id will always be set to -1. The optional fields
1956d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are supported as a set. Either they are all valid, or none of them
1957d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are.
1958d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1959d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public int id = -1;
1960d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1961d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1962d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the left eye. The coordinates are in
1963d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1964d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1965d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1966d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1967d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1968d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point leftEye = null;
1969d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1970d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1971d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the right eye. The coordinates are
1972d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * in the same space as the ones for {@link #rect}.This is an optional
1973d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1974d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1975d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1976d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1977d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point rightEye = null;
1978d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1979d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1980d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the mouth.  The coordinates are in
1981d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1982d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1983d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1984d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1985d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1986d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point mouth = null;
19874c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
19884c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1989bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1990bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unspecified camera error.
1991bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1992bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
19939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_UNKNOWN = 1;
1994bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1995bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1996e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     * Camera was disconnected due to use by higher priority user.
1997e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     * @see Camera.ErrorCallback
1998e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk     */
1999e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk    public static final int CAMERA_ERROR_EVICTED = 2;
2000e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk
2001e91b92546e645191f0fbcc681740d3c4081161dcRuben Brunk    /**
2002bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Media server died. In this case, the application must release the
2003bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera object and instantiate a new one.
2004bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
2005bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
20069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_SERVER_DIED = 100;
20079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
20089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2009bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for camera error notification.
2010bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
2011bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setErrorCallback(ErrorCallback)
2012b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
2013b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2014b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
20159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2016b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
20179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ErrorCallback
20189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
20199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
20209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Callback for camera errors.
20219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param error   error code:
20229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <ul>
20239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_UNKNOWN}
20249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_SERVER_DIED}
20259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * </ul>
20269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
20279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
20289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onError(int error, Camera camera);
20299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
20309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
20329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Registers a callback to be invoked when an error occurs.
2033bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb The callback to run
20349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
20359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setErrorCallback(ErrorCallback cb)
20369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
20379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mErrorCallback = cb;
20389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
20399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
20409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_setParameters(String params);
20419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final String native_getParameters();
20429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2044bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Changes the settings for this Camera service.
20459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
20469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param params the Parameters to use for this Camera service
204799a3f3e4e06b4370101ca97cc11dbe81d772fefaWu-cheng Li     * @throws RuntimeException if any parameter is invalid or not supported.
2048bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #getParameters()
20499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
20509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setParameters(Parameters params) {
20517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // If using preview allocations, don't allow preview size changes
20527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (mUsingPreviewAllocation) {
20537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size newPreviewSize = params.getPreviewSize();
20547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size currentPreviewSize = getParameters().getPreviewSize();
20557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            if (newPreviewSize.width != currentPreviewSize.width ||
20567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                    newPreviewSize.height != currentPreviewSize.height) {
20577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                throw new IllegalStateException("Cannot change preview size" +
20587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        " while a preview allocation is configured.");
20597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            }
20607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
20617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
20629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_setParameters(params.flatten());
20639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
20649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2066bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Returns the current settings for this Camera service.
2067bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * If modifications are made to the returned Parameters, they must be passed
2068bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to {@link #setParameters(Camera.Parameters)} to take effect.
2069bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
207006a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     * @throws RuntimeException if reading parameters fails; usually this would
207106a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    be because of a hardware or other low-level error, or because
207206a771813bc4796501fb91532ca77aaf9c2e0390Eino-Ville Talvala     *    release() has been called on this Camera instance.
2073bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setParameters(Camera.Parameters)
20749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
20759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public Parameters getParameters() {
20769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Parameters p = new Parameters();
20779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String s = native_getParameters();
20789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        p.unflatten(s);
20799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return p;
20809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
20819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
20829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
20831c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * Returns an empty {@link Parameters} for testing purpose.
20841c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
2085f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * @return a Parameter object.
20861c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
20871c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * @hide
20881c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
20891c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    public static Parameters getEmptyParameters() {
20901c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        Camera camera = new Camera();
20911c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        return camera.new Parameters();
20921c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
20931c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
20941c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
2095df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * Returns a copied {@link Parameters}; for shim use only.
2096df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     *
2097df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @param parameters a non-{@code null} parameters
2098df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @return a Parameter object, with all the parameters copied from {@code parameters}.
2099df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     *
2100df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @throws NullPointerException if {@code parameters} was {@code null}
2101df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     * @hide
2102df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin     */
2103df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    public static Parameters getParametersCopy(Camera.Parameters parameters) {
2104df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        if (parameters == null) {
2105df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            throw new NullPointerException("parameters must not be null");
2106df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
2107df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2108df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        Camera camera = parameters.getOuter();
2109df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        Parameters p = camera.new Parameters();
2110df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        p.copyFrom(parameters);
2111df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2112df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        return p;
2113df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    }
2114df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2115df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin    /**
2116bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Image size (width and height dimensions).
2117b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2118b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
21199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2120b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
21219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Size {
21229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
21239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the dimensions for pictures.
21249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param w the photo width (pixels)
21269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param h the photo height (pixels)
21279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
21289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size(int w, int h) {
21299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            width = w;
21309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            height = h;
21319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21324c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
21334c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Compares {@code obj} to this size.
21344c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
21354c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @param obj the object to compare this size with.
21364c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @return {@code true} if the width and height of {@code obj} is the
21374c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         same as those of this size. {@code false} otherwise.
21384c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
21394c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
21404c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public boolean equals(Object obj) {
21414c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            if (!(obj instanceof Size)) {
21424c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li                return false;
21434c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            }
21444c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            Size s = (Size) obj;
21454c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width == s.width && height == s.height;
21464c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
21474c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
21484c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public int hashCode() {
21494c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width * 32713 + height;
21504c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
21519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** width of the picture */
21529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int width;
21539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** height of the picture */
21549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int height;
21559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
21569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
215832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The Area class is used for choosing specific metering and focus areas for
215932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the camera to use when calculating auto-exposure, auto-white balance, and
216032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * auto-focus.</p>
216132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
216232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>To find out how many simultaneous areas a given camera supports, use
216332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumMeteringAreas()} and
216432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
216532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * selection is unsupported, these methods will return 0.</p>
216632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
216732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Each Area consists of a rectangle specifying its bounds, and a weight
216832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * that determines its importance. The bounds are relative to the camera's
216932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * current field of view. The coordinates are mapped so that (-1000, -1000)
217032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * is always the top-left corner of the current field of view, and (1000,
217132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * 1000) is always the bottom-right corner of the current field of
217232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * view. Setting Areas with bounds outside that range is not allowed. Areas
217332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * with zero or negative width or height are not allowed.</p>
217432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
217532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The weight must range from 1 to 1000, and represents a weight for
217632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * every pixel in the area. This means that a large metering area with
217732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the same weight as a smaller area will have more effect in the
217832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * metering result.  Metering areas can overlap and the driver
217932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * will add the weights in the overlap region.</p>
2180bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     *
2181bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setFocusAreas(List)
2182bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getFocusAreas()
2183bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumFocusAreas()
2184bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setMeteringAreas(List)
2185bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMeteringAreas()
2186bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumMeteringAreas()
2187b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
2188b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2189b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
219030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li     */
2191b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
219230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    public static class Area {
219330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
219430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Create an area with specified rectangle and weight.
219530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
219632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param rect the bounds of the area.
219732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param weight the weight of the area.
219830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
219930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Area(Rect rect, int weight) {
220030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.rect = rect;
220130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.weight = weight;
220230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
220330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
220430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Compares {@code obj} to this area.
220530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
220630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @param obj the object to compare this area with.
220730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return {@code true} if the rectangle and weight of {@code obj} is
220830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *         the same as those of this area. {@code false} otherwise.
220930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
221030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        @Override
221130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public boolean equals(Object obj) {
221230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (!(obj instanceof Area)) {
221330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return false;
221430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
221530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            Area a = (Area) obj;
221630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (rect == null) {
221730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (a.rect != null) return false;
221830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } else {
221930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (!rect.equals(a.rect)) return false;
222030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
222130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return weight == a.weight;
222230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
222330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
2224bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
222532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Bounds of the area. (-1000, -1000) represents the top-left of the
222632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * camera field of view, and (1000, 1000) represents the bottom-right of
222732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the field of view. Setting bounds outside that range is not
222832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed. Bounds with zero or negative width or height are not
222932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed.
2230bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
2231bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
2232bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
2233bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
223430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Rect rect;
223530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
2236bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
223732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Weight of the area. The weight must range from 1 to 1000, and
223832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * represents a weight for every pixel in the area. This means that a
223932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * large metering area with the same weight as a smaller area will have
224032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * more effect in the metering result.  Metering areas can overlap and
224132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the driver will add the weights in the overlap region.
2242bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
2243bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
2244bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
2245bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
224630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int weight;
2247bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li    }
224830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
224930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    /**
2250bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera service settings.
22519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
22529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>To make camera parameters take effect, applications have to call
2253bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera#setParameters(Camera.Parameters)}. For example, after
2254bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
2255bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * actually changed until {@link Camera#setParameters(Camera.Parameters)}
2256bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with the changed parameters object.
22579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
22589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>Different devices may have different camera capabilities, such as
22599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * picture size or flash modes. The application should query the camera
22609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * capabilities before setting parameters. For example, the application
2261bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * should call {@link Camera.Parameters#getSupportedColorEffects()} before
2262bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling {@link Camera.Parameters#setColorEffect(String)}. If the
2263bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera does not support color effects,
2264bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
2265b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *
2266b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     * @deprecated We recommend using the new {@link android.hardware.camera2} API for new
2267b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala     *             applications.
22689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2269b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala    @Deprecated
22709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Parameters {
22719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter keys to communicate with the camera driver.
22729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_SIZE = "preview-size";
22739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FORMAT = "preview-format";
22749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
2275454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
22769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_SIZE = "picture-size";
22779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_FORMAT = "picture-format";
22784c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
22799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
22809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
22819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
22829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_QUALITY = "jpeg-quality";
22839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ROTATION = "rotation";
22849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LATITUDE = "gps-latitude";
22859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LONGITUDE = "gps-longitude";
22869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_ALTITUDE = "gps-altitude";
22879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
2288055c986ab841f8f758398841730f1e90313b132aRay Chen        private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
22899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_WHITE_BALANCE = "whitebalance";
22909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_EFFECT = "effect";
22919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ANTIBANDING = "antibanding";
22929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_SCENE_MODE = "scene-mode";
22939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_FLASH_MODE = "flash-mode";
229436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        private static final String KEY_FOCUS_MODE = "focus-mode";
229530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_FOCUS_AREAS = "focus-areas";
229630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
22976c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_FOCAL_LENGTH = "focal-length";
22986c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
22996c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
2300ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
230124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
230224b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
230324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
23043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
23053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
2306d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
2307d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
2308e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_METERING_AREAS = "metering-areas";
2309e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
23108cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM = "zoom";
23118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_MAX_ZOOM = "max-zoom";
23128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
23138cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
23148cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
2315e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        private static final String KEY_FOCUS_DISTANCES = "focus-distances";
2316dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_VIDEO_SIZE = "video-size";
2317dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
2318dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong                                            "preferred-preview-size-for-video";
23194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
23204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
232125d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        private static final String KEY_RECORDING_HINT = "recording-hint";
232298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
2323037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
2324037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
2325e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
23269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter key suffix for supported values.
23279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String SUPPORTED_VALUES_SUFFIX = "-values";
23289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
23298cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String TRUE = "true";
23303773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String FALSE = "false";
23318cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li
23329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for white balance settings.
23339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_AUTO = "auto";
23349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
23359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
23369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
23379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
23389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
23399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_TWILIGHT = "twilight";
23409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_SHADE = "shade";
23419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
23429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for color effect settings.
23439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NONE = "none";
23449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_MONO = "mono";
23459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NEGATIVE = "negative";
23469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SOLARIZE = "solarize";
23479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SEPIA = "sepia";
23489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_POSTERIZE = "posterize";
23499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_WHITEBOARD = "whiteboard";
23509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_BLACKBOARD = "blackboard";
23519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_AQUA = "aqua";
23529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
23539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for antibanding settings.
23549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_AUTO = "auto";
23559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_50HZ = "50hz";
23569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_60HZ = "60hz";
23579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_OFF = "off";
23589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
23599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for flash mode settings.
23609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
23619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will not be fired.
23629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_OFF = "off";
236436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
23659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2366068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will be fired automatically when required. The flash may be fired
2367068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * during preview, auto-focus, or snapshot depending on the driver.
23689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_AUTO = "auto";
237036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
23719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2372068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will always be fired during snapshot. The flash may also be
2373068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * fired during preview or auto-focus depending on the driver.
23749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_ON = "on";
237636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
23779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
23789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will be fired in red-eye reduction mode.
23799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_RED_EYE = "red-eye";
238136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
238236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
2383068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Constant emission of light during preview, auto-focus and snapshot.
2384068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * This can also be used for video recording.
238536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
2386068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li        public static final String FLASH_MODE_TORCH = "torch";
23879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
238800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
238900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Scene mode is off.
239000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
23919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_AUTO = "auto";
239200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
239300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
239400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
239500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_SPORTS}.
239600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
23979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_ACTION = "action";
239800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
239900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
240000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures.
240100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PORTRAIT = "portrait";
240300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
240400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
240500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on distant objects.
240600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_LANDSCAPE = "landscape";
240800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
240900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
241000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos at night.
241100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT = "night";
241300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
241400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
241500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures at night.
241600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
241800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
241900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
242000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos in a theater. Flash light is off.
242100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_THEATRE = "theatre";
242300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
242400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
242500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the beach.
242600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_BEACH = "beach";
242800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
242900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
243000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the snow.
243100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SNOW = "snow";
243300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
243400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
243500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take sunset photos.
243600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SUNSET = "sunset";
243800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
243900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
244000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Avoid blurry pictures (for example, due to hand shake).
244100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
244300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
244400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
244500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * For shooting firework displays.
244600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_FIREWORKS = "fireworks";
244800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
244900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
245000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
245100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_ACTION}.
245200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SPORTS = "sports";
245400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
245500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
245600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take indoor low-light shot.
245700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PARTY = "party";
245900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
246000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
246100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Capture the naturally warm color of scenes lit by candles.
246200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
24639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
24649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
2465c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2466c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Applications are looking for a barcode. Camera driver will be
2467c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * optimized for barcode reading.
2468c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2469c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String SCENE_MODE_BARCODE = "barcode";
2470c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
247136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
2472da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * Capture a scene using high dynamic range imaging techniques. The
2473da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * camera will return an image that has an extended dynamic range
2474da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * compared to a regular capture. Capturing such an image may take
2475da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * longer than a regular capture.
2476da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         */
2477da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        public static final String SCENE_MODE_HDR = "hdr";
2478da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala
2479da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        /**
2480f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Auto-focus mode. Applications should call {@link
2481f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
248236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
248336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_AUTO = "auto";
248436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
248536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
248636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is set at infinity. Applications should not call
248736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} in this mode.
248836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
248936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_INFINITY = "infinity";
2490f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li
2491f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li        /**
2492f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Macro (close-up) focus mode. Applications should call
2493f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2494f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * mode.
2495f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         */
249636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_MACRO = "macro";
249736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
249836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
249936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is fixed. The camera is always in this mode if the focus is not
250036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * adjustable. If the camera has auto-focus, this mode can fix the
250136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * focus, which is usually at hyperfocal distance. Applications should
250236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
250336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
250436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_FIXED = "fixed";
250536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
2506c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2507c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Extended depth of field (EDOF). Focusing is done digitally and
2508c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * continuously. Applications should not call {@link
2509c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode.
2510c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2511c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String FOCUS_MODE_EDOF = "edof";
2512c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
2513699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li        /**
2514d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * Continuous auto focus mode intended for video recording. The camera
2515b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. This is the best choice for video
2516b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * recording because the focus changes smoothly . Applications still can
2517b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * call {@link #takePicture(Camera.ShutterCallback,
2518b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2519b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * subject may not be in focus. Auto focus starts when the parameter is
252053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * set.
252153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
252253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * <p>Since API level 14, applications can call {@link
252353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
252453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * immediately return with a boolean that indicates whether the focus is
252553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * sharp or not. The focus position is locked after autoFocus call. If
252653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * applications want to resume the continuous focus, cancelAutoFocus
252753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * must be called. Restarting the preview will not resume the continuous
252853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * autofocus. To stop continuous focus, applications should change the
252953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * focus mode to other modes.
253053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
253153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_PICTURE
2532d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         */
2533d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
2534699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li
2535b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        /**
2536b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Continuous auto focus mode intended for taking pictures. The camera
2537b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. The speed of focus change is more
2538b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
253953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * starts when the parameter is set.
254053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
25410f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
25420f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * this mode. If the autofocus is in the middle of scanning, the focus
25430f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * callback will return when it completes. If the autofocus is not
25440f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * scanning, the focus callback will immediately return with a boolean
25450f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * that indicates whether the focus is sharp or not. The apps can then
25460f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * decide if they want to take a picture immediately or to change the
25470f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * focus mode to auto, and run a full autofocus cycle. The focus
25480f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * position is locked after autoFocus call. If applications want to
25490f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * resume the continuous focus, cancelAutoFocus must be called.
25500f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * Restarting the preview will not resume the continuous autofocus. To
25510f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * stop continuous focus, applications should change the focus mode to
25520f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * other modes.
2553b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         *
2554b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
2555b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         */
2556b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2557b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li
2558e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Indices for focus distance array.
2559e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2560e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of near focus distance for use with
2561e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2562e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2563e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2564e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2565e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2566e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of optimal focus distance for use with
2567e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2568e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2569e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2570e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2571e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2572e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of far focus distance for use with
2573e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2574e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2575e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2576e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2577ca099614841bc619f217dfa088da630a7eb1ab65Wu-cheng Li        /**
2578454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of minimum preview fps for use with {@link
2579454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2580454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2581454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2582454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MIN_INDEX = 0;
2583454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2584454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2585454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of maximum preview fps for use with {@link
2586454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2587454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2588454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2589454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MAX_INDEX = 1;
2590454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
25919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Formats for setPreviewFormat and setPictureFormat.
25929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
25939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
2594eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang        private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
259510a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
25969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_RGB565 = "rgb565";
25979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_JPEG = "jpeg";
259870fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li        private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
25999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26007d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        /**
26017d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * Order matters: Keys that are {@link #set(String, String) set} later
26027d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * will take precedence over keys that are set earlier (if the two keys
26037d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * conflict with each other).
26047d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         *
26057d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it
26067d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later
26077d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * is the one that will take precedence.
26087d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         * </p>
26097d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin         */
26107d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        private final LinkedHashMap<String, String> mMap;
26119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Parameters() {
26137d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64);
26149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2617df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * Overwrite existing parameters with a copy of the ones from {@code other}.
2618df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         *
2619df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * <b>For use by the legacy shim only.</b>
2620df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         *
2621df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         * @hide
2622df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin         */
2623df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        public void copyFrom(Parameters other) {
2624df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            if (other == null) {
2625df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin                throw new NullPointerException("other must not be null");
2626df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            }
2627df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2628df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            mMap.putAll(other.mMap);
2629df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
2630df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2631df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        private Camera getOuter() {
2632df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin            return Camera.this;
2633df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        }
2634df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin
2635d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk
2636d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        /**
2637d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         * Value equality check.
2638d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         *
2639d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         * @hide
2640d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk         */
2641d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        public boolean same(Parameters other) {
2642d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            if (this == other) {
2643d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk                return true;
2644d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            }
2645d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk            return other != null && Parameters.this.mMap.equals(other.mMap);
2646d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk        }
2647d1f113d0f0ce5099f8efba40a88398f7945bb5e0Ruben Brunk
2648df6242e374b81e802a38cb891477f05d3e4b3cbcIgor Murashkin        /**
26499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Writes the current Parameters to the log.
26509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @hide
26519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @deprecated
26529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
2653a1d662716b3da384dfe3a758f079e0cbd089784aIgor Murashkin        @Deprecated
26549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void dump() {
26559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Log.e(TAG, "dump: size=" + mMap.size());
26569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
26579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
26589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
26599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Creates a single string with all the parameters set in
26639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
26649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #unflatten(String)} method does the reverse.</p>
26659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return a String with all values from this Parameters object, in
26679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *         semi-colon delimited key-value pairs
26689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String flatten() {
26700a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            StringBuilder flattened = new StringBuilder(128);
26719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
26729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(k);
26739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append("=");
26749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(mMap.get(k));
26759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(";");
26769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
26779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            // chop off the extra semicolon at the end
26789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            flattened.deleteCharAt(flattened.length()-1);
26799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return flattened.toString();
26809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Takes a flattened string of parameters and adds each one to
26849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
26859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #flatten()} method does the reverse.</p>
26869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param flattened a String of parameters (key-value paired) that
26889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *                  are semi-colon delimited
26899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void unflatten(String flattened) {
26919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.clear();
26929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26930a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
26940a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(flattened);
26950a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String kv : splitter) {
26969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int pos = kv.indexOf('=');
26979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (pos == -1) {
26989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    continue;
26999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
27009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String k = kv.substring(0, pos);
27019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String v = kv.substring(pos + 1);
27029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                mMap.put(k, v);
27039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
27049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
27069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void remove(String key) {
27079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.remove(key);
27089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets a String parameter.
27129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
27149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the String value of the parameter
27159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, String value) {
2717cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2718cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
27199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
27209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
2721cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2722cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
27239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
27249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
27259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27267d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            put(key, value);
27279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets an integer parameter.
27319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
27339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the int value of the parameter
27349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, int value) {
27367d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            put(key, Integer.toString(value));
27377d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        }
27387d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin
27397d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin        private void put(String key, String value) {
27407d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            /*
27417d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * Remove the key if it already exists.
27427d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             *
27437d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * This way setting a new value for an already existing key will always move
27447d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             * that key to be ordered the latest in the map.
27457d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin             */
27467d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap.remove(key);
27477d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin            mMap.put(key, value);
27489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2750e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private void set(String key, List<Area> areas) {
2751f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (areas == null) {
2752f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, "(0,0,0,0,0)");
2753f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            } else {
2754f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                StringBuilder buffer = new StringBuilder();
2755f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                for (int i = 0; i < areas.size(); i++) {
2756f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Area area = areas.get(i);
2757f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Rect rect = area.rect;
2758f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append('(');
2759f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.left);
2760f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2761f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.top);
2762f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2763f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.right);
2764f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2765f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.bottom);
2766f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2767f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(area.weight);
2768f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(')');
2769f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    if (i != areas.size() - 1) buffer.append(',');
2770f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
2771f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, buffer.toString());
2772e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            }
2773e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
2774e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
27759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of a String parameter.
27779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
27799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the String value of the parameter
27809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String get(String key) {
27829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mMap.get(key);
27839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of an integer parameter.
27879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
27899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the int value of the parameter
27909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getInt(String key) {
27929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return Integer.parseInt(mMap.get(key));
27939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
279626274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * Sets the dimensions for preview pictures. If the preview has already
279726274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * started, applications should stop the preview first before changing
279826274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * preview size.
27999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2800c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * The sides of width and height are based on camera orientation. That
2801c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * is, the preview size is the size before it is rotated by display
2802c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation. So applications need to consider the display orientation
2803c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * while setting preview size. For example, suppose the camera supports
2804c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2805c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * preview ratio. If the display orientation is set to 0 or 180, preview
2806c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * size should be set to 480x320. If the display orientation is set to
2807c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * 90 or 270, preview size should be set to 320x480. The display
2808c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation should also be considered while setting picture size and
2809c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * thumbnail size.
2810c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
28119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the pictures, in pixels
28129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the pictures, in pixels
2813c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setDisplayOrientation(int)
2814c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
2815c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPictureSize(int, int)
2816c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setJpegThumbnailSize(int, int)
28179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
28189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewSize(int width, int height) {
28199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
28209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_SIZE, v);
28219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
28229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
28239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
28249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimensions setting for preview pictures.
28259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2826dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a Size object with the width and height setting
28279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for the preview picture
28289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
28299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPreviewSize() {
28309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PREVIEW_SIZE);
28319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
28329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
28349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview sizes.
28369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
28389c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li         *         with at least one element.
28399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPreviewSizes() {
28419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
28429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
28439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
28449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
28459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
284632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the supported video frame sizes that can be used by
284732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * MediaRecorder.</p>
2848dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
284932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>If the returned list is not null, the returned list will contain at
2850dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * least one Size and one of the sizes in the returned list must be
2851dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * passed to MediaRecorder.setVideoSize() for camcorder application if
2852dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * camera is used as the video source. In this case, the size of the
2853dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview can be different from the resolution of the recorded video
285432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * during video recording.</p>
2855dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2856dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a list of Size object if camera has separate preview and
2857dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video output; otherwise, null is returned.
2858dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getPreferredPreviewSizeForVideo()
2859dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2860dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public List<Size> getSupportedVideoSizes() {
2861dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2862dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return splitSize(str);
2863dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2864dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2865dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
2866dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * Returns the preferred or recommended preview size (width and height)
2867dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * in pixels for video recording. Camcorder applications should
2868dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * set the preview size to a value that is not larger than the
2869dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preferred preview size. In other words, the product of the width
2870dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * and height of the preview size should not be larger than that of
2871dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * the preferred preview size. In addition, we recommend to choose a
2872dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview size that has the same aspect ratio as the resolution of
2873dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * video to be recorded.
2874dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2875dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return the preferred preview size (width and height) in pixels for
2876dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video recording if getSupportedVideoSizes() does not return
2877dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         null; otherwise, null is returned.
2878dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getSupportedVideoSizes()
2879dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2880dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public Size getPreferredPreviewSizeForVideo() {
2881dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2882dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return strToSize(pair);
2883dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2884dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2885dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
288632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
28874c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * applications set both width and height to 0, EXIF will not contain
288832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * thumbnail.</p>
28899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
289032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
289132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2892c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
28939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the thumbnail, in pixels
28949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the thumbnail, in pixels
2895c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
28969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailSize(int width, int height) {
28989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
28999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
29009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the dimensions for EXIF thumbnail in Jpeg picture.
29049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
29059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting for the EXIF
29069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         thumbnails
29079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public Size getJpegThumbnailSize() {
29099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
29109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                            getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
29119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29144c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Gets the supported jpeg thumbnail sizes.
29154c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
29163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
29174c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         with at least two elements. Size 0,0 (no thumbnail) is always
29184c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         supported.
29194c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
29204c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public List<Size> getSupportedJpegThumbnailSizes() {
29214c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
29224c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return splitSize(str);
29234c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
29244c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li
29254c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
29269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the quality of the EXIF thumbnail in Jpeg picture.
29279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
29289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
29299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
29309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailQuality(int quality) {
29329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
29339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
29379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
29389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG quality setting of the EXIF thumbnail.
29399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegThumbnailQuality() {
29419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
29429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
29459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets Jpeg quality of captured picture.
29469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
29479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of captured picture. The range is 1
29489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
29499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegQuality(int quality) {
29519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_QUALITY, quality);
29529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the JPEG picture.
29569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG picture quality setting.
29589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegQuality() {
29609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_QUALITY);
29619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2964a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Sets the rate at which preview frames are received. This is the
2965a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * target frame rate. The actual frame rate depends on the driver.
29669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param fps the frame rate (frames per second)
29685f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
29699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29705f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
29719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFrameRate(int fps) {
29729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FRAME_RATE, fps);
29739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
29749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
29759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2976a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Returns the setting for the rate at which preview frames are
2977a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * received. This is the target frame rate. The actual frame rate
2978a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * depends on the driver.
29799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the frame rate setting (frames per second)
29815f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
29829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
29835f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
29849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFrameRate() {
29859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_PREVIEW_FRAME_RATE);
29869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview frame rates.
29909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview frame rates. null if preview
29923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         frame rate setting is not supported.
29935f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
29949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29955f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
29969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFrameRates() {
29979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
29989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitInt(str);
29999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
30009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
30019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
30024a68e3c26dd2512c319071dc20074baa6e7d171fHai Guo         * Sets the minimum and maximum preview fps. This controls the rate of
30031620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li         * preview frames received in {@link PreviewCallback}. The minimum and
3004454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum preview fps must be one of the elements from {@link
3005454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange}.
3006454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
3007454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param min the minimum preview fps (scaled by 1000).
3008454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param max the maximum preview fps (scaled by 1000).
3009454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @throws RuntimeException if fps range is invalid.
3010454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
3011454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
3012454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
3013454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void setPreviewFpsRange(int min, int max) {
3014454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
3015454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
3016454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3017454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
3018454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Returns the current minimum and maximum preview fps. The values are
3019454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
3020454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
3021454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return range the minimum and maximum preview fps (scaled by 1000).
3022454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
3023454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
3024454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
3025454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
3026454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void getPreviewFpsRange(int[] range) {
3027454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (range == null || range.length != 2) {
3028454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                throw new IllegalArgumentException(
30295f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li                        "range must be an array with two elements.");
3030454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
3031454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
3032454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
3033454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3034454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
3035454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Gets the supported preview fps (frame-per-second) ranges. Each range
3036454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * contains a minimum fps and maximum fps. If minimum fps equals to
3037454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum fps, the camera outputs frames in fixed frame rate. If not,
3038454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * the camera outputs frames in auto frame rate. The actual frame rate
3039454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * fluctuates between the minimum and the maximum. The values are
3040454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * multiplied by 1000 and represented in integers. For example, if frame
3041454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * rate is 26.623 frames per second, the value is 26623.
3042454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
3043454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return a list of supported preview fps ranges. This method returns a
3044454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         list with at least one element. Every element is an int array
3045454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         of two values - minimum fps and maximum fps. The list is
3046454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         sorted from small to large (first by maximum fps and then
3047454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         minimum fps).
3048454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
3049454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
3050454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
3051454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public List<int[]> getSupportedPreviewFpsRange() {
3052454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
3053454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return splitRange(str);
3054454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
3055454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3056454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
30577478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         * Sets the image format for preview pictures.
3058da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         * <p>If this is never called, the default format will be
3059a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * {@link android.graphics.ImageFormat#NV21}, which
3060df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         * uses the NV21 encoding format.</p>
30617478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
3062951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
3063951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the available preview formats.
3064951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
3065951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>It is strongly recommended that either
3066951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#NV21} or
3067951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12} is used, since
3068951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * they are supported by all camera devices.</p>
3069951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
3070951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>For YV12, the image buffer that is received is not necessarily
3071951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * tightly packed, as there may be padding at the end of each row of
3072951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * pixel data, as described in
3073951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
3074951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * it can be assumed that the stride of the Y and UV data is the
3075951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * smallest possible that meets the alignment requirements. That is, if
3076951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the preview size is <var>width x height</var>, then the following
3077951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * equations describe the buffer index for the beginning of row
3078951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <var>y</var> for the Y plane and row <var>c</var> for the U and V
3079951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * planes:
3080951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
308171fbb81b14958b80fe55738607740c6630e4e9daNeil Fuller         * <pre>{@code
3082951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yStride   = (int) ceil(width / 16.0) * 16;
3083951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvStride  = (int) ceil( (yStride / 2) / 16.0) * 16;
3084951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * ySize     = yStride * height;
3085951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvSize    = uvStride * height / 2;
3086951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yRowIndex = yStride * y;
3087951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uRowIndex = ySize + uvSize + uvStride * c;
3088951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * vRowIndex = ySize + uvStride * c;
308971fbb81b14958b80fe55738607740c6630e4e9daNeil Fuller         * size      = ySize + uvSize * 2;
3090951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * }
309171fbb81b14958b80fe55738607740c6630e4e9daNeil Fuller         *</pre>
3092951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
3093951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @param pixel_format the desired preview picture format, defined by
3094951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   one of the {@link android.graphics.ImageFormat} constants.  (E.g.,
3095951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.NV21</var> (default), or
3096951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.YV12</var>)
3097951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
3098a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
3099951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
31009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
31019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFormat(int pixel_format) {
31029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
31039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
31049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
31059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
31069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
31079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FORMAT, s);
31099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
31109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
31123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * Returns the image format for preview frames got from
31139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * {@link PreviewCallback}.
31147478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
31153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the preview format.
31163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
3117951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
31189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
31199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFormat() {
31209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
31219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
31239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3124f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
3125f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported. {@link android.graphics.ImageFormat#YV12}
3126f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported since API level 12.
31279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview formats. This method will always
31293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
31303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
3131951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
31329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFormats() {
31349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
3135eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            ArrayList<Integer> formats = new ArrayList<Integer>();
3136eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            for (String s : split(str)) {
3137eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                int f = pixelFormatForCameraFormat(s);
3138a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
3139eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                formats.add(f);
3140eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            }
3141eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            return formats;
31429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
31439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
314532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for pictures.</p>
31469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
314732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
314832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
3149c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
31509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width for pictures, in pixels
31519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height for pictures, in pixels
3152c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
3153c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
31549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
31559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureSize(int width, int height) {
31569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
31579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_SIZE, v);
31589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
31599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
31619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimension setting for pictures.
31629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting
31649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for pictures
31659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
31669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPictureSize() {
31679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PICTURE_SIZE);
31689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
31699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
31729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture sizes.
31739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported picture sizes. This method will always
31753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
31769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPictureSizes() {
31789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
31799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
31809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
31819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
31839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the image format for pictures.
31849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param pixel_format the desired picture format
3186a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                     (<var>ImageFormat.NV21</var>,
3187a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.RGB_565</var>, or
3188a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.JPEG</var>)
3189a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
31909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
31919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureFormat(int pixel_format) {
31929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
31939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
31949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
31959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
31969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
31979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
31989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_FORMAT, s);
31999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
32009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
32029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the image format for pictures.
32039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the picture format
32053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
32069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
32079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPictureFormat() {
32089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
32099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
32109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
32119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture formats.
32139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
32143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return supported picture formats. This method will always return a
32153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         list with at least one element.
32163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
32179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
32189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPictureFormats() {
32199c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
32209c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            ArrayList<Integer> formats = new ArrayList<Integer>();
32219c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            for (String s : split(str)) {
32229c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                int f = pixelFormatForCameraFormat(s);
3223a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
32249c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                formats.add(f);
32259c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            }
32269c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            return formats;
32279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
32289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private String cameraFormatForPixelFormat(int pixel_format) {
32309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(pixel_format) {
3231a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV16:      return PIXEL_FORMAT_YUV422SP;
3232a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV21:      return PIXEL_FORMAT_YUV420SP;
3233a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.YUY2:      return PIXEL_FORMAT_YUV422I;
323410a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            case ImageFormat.YV12:      return PIXEL_FORMAT_YUV420P;
3235a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.RGB_565:   return PIXEL_FORMAT_RGB565;
3236a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.JPEG:      return PIXEL_FORMAT_JPEG;
3237a696f5d667227365da732481770767dcb330dd23Mathias Agopian            default:                    return null;
32389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
32399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
32409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private int pixelFormatForCameraFormat(String format) {
32429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (format == null)
3243a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.UNKNOWN;
32449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV422SP))
3246a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV16;
32479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420SP))
3249a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV21;
32509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3251eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            if (format.equals(PIXEL_FORMAT_YUV422I))
3252a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.YUY2;
3253eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang
325410a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420P))
325510a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li                return ImageFormat.YV12;
325610a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li
32579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_RGB565))
3258a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.RGB_565;
32599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_JPEG))
3261a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.JPEG;
32629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3263a696f5d667227365da732481770767dcb330dd23Mathias Agopian            return ImageFormat.UNKNOWN;
32649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
32659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
32669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
32678969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * Sets the clockwise rotation angle in degrees relative to the
32688969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * orientation of the camera. This affects the pictures returned from
32698969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * JPEG {@link PictureCallback}. The camera driver may set orientation
32708969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * in the EXIF header without rotating the picture. Or the driver may
32718969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
3272a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotated, the orientation in the EXIF header will be missing or 1 (row
3273a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * #0 is top and column #0 is left side).
3274a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
3275a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
3276a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * If applications want to rotate the picture to match the orientation
3277a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * of what users see, apps should use
3278a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.view.OrientationEventListener} and
3279a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.hardware.Camera.CameraInfo}. The value from
3280a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * OrientationEventListener is relative to the natural orientation of
3281a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the device. CameraInfo.orientation is the angle between camera
3282a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * orientation and natural device orientation. The sum of the two is the
3283a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotation angle for back-facing camera. The difference of the two is
3284a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the rotation angle for front-facing camera. Note that the JPEG
3285a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * pictures of front-facing cameras are not mirrored as in preview
3286a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * display.
3287a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
3288a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
3289a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * For example, suppose the natural orientation of the device is
32902fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * portrait. The device is rotated 270 degrees clockwise, so the device
32912fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 270. Suppose a back-facing camera sensor is mounted in
32922fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * landscape and the top side of the camera sensor is aligned with the
32932fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the display in natural orientation. So the camera
32942fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 90. The rotation should be set to 0 (270 + 90).
32952fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
329669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>The reference code is as follows.
32972fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
3298e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * <pre>
32999a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main         * public void onOrientationChanged(int orientation) {
33002fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     if (orientation == ORIENTATION_UNKNOWN) return;
33012fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.CameraInfo info =
33022fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *            new android.hardware.Camera.CameraInfo();
33032fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.getCameraInfo(cameraId, info);
33042fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     orientation = (orientation + 45) / 90 * 90;
33052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     int rotation = 0;
33062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
33072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation - orientation + 360) % 360;
33082fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     } else {  // back-facing camera
33092fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation + orientation) % 360;
33102fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     }
33112fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     mParameters.setRotation(rotation);
33122fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * }
3313e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * </pre>
33142fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
33152fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @param rotation The rotation angle in degrees relative to the
33162fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 orientation of the camera. Rotation can only be 0,
33172fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 90, 180 or 270.
33189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @throws IllegalArgumentException if rotation value is invalid.
33199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @see android.view.OrientationEventListener
33202fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
33219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setRotation(int rotation) {
33239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (rotation == 0 || rotation == 90 || rotation == 180
33249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                    || rotation == 270) {
33259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                set(KEY_ROTATION, Integer.toString(rotation));
33269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            } else {
33279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
33289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid rotation=" + rotation);
33299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
33309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
33349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
33359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param latitude GPS latitude coordinate.
33379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLatitude(double latitude) {
33399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LATITUDE, Double.toString(latitude));
33409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
33449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
33459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param longitude GPS longitude coordinate.
33479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLongitude(double longitude) {
33499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LONGITUDE, Double.toString(longitude));
33509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS altitude. This will be stored in JPEG EXIF header.
33549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param altitude GPS altitude in meters.
33569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsAltitude(double altitude) {
33589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_ALTITUDE, Double.toString(altitude));
33599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS timestamp. This will be stored in JPEG EXIF header.
33639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param timestamp GPS timestamp (UTC in seconds since January 1,
33659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                  1970).
33669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsTimestamp(long timestamp) {
33689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
33699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3372d8407271ffa83d27e9a524f485a0799e422e1fd6Eino-Ville Talvala         * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes
3373d8407271ffa83d27e9a524f485a0799e422e1fd6Eino-Ville Talvala         * long, in the JPEG EXIF header.
3374055c986ab841f8f758398841730f1e90313b132aRay Chen         *
3375055c986ab841f8f758398841730f1e90313b132aRay Chen         * @param processing_method The processing method to get this location.
3376055c986ab841f8f758398841730f1e90313b132aRay Chen         */
3377055c986ab841f8f758398841730f1e90313b132aRay Chen        public void setGpsProcessingMethod(String processing_method) {
3378055c986ab841f8f758398841730f1e90313b132aRay Chen            set(KEY_GPS_PROCESSING_METHOD, processing_method);
3379055c986ab841f8f758398841730f1e90313b132aRay Chen        }
3380055c986ab841f8f758398841730f1e90313b132aRay Chen
3381055c986ab841f8f758398841730f1e90313b132aRay Chen        /**
33829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Removes GPS latitude, longitude, altitude, and timestamp from the
33839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * parameters.
33849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
33859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void removeGpsData() {
33869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LATITUDE);
33879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LONGITUDE);
33889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_ALTITUDE);
33899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_TIMESTAMP);
3390055c986ab841f8f758398841730f1e90313b132aRay Chen            remove(KEY_GPS_PROCESSING_METHOD);
33919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
33929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
33939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
33949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current white balance setting.
33959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
33963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current white balance. null if white balance setting is not
33973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
33983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_AUTO
33993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_INCANDESCENT
34003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_FLUORESCENT
34013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_WARM_FLUORESCENT
34023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_DAYLIGHT
34033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
34043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_TWILIGHT
34053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_SHADE
34063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *
34079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getWhiteBalance() {
34099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_WHITE_BALANCE);
34109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
341316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * Sets the white balance. Changing the setting will release the
3414b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * auto-white balance lock. It is recommended not to change white
3415b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * balance and AWB lock at the same time.
34169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new white balance.
34183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
3419037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
34209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setWhiteBalance(String value) {
3422b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            String oldValue = get(KEY_WHITE_BALANCE);
3423b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (same(value, oldValue)) return;
34249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_WHITE_BALANCE, value);
342516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
34269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported white balance.
34309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported white balance. null if white balance
34323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
34333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
34349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedWhiteBalance() {
34369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
34379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
34389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current color effect setting.
34429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34433f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current color effect. null if color effect
34449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
34453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NONE
34463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_MONO
34473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NEGATIVE
34483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SOLARIZE
34493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SEPIA
34503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_POSTERIZE
34513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_WHITEBOARD
34523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_BLACKBOARD
34533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_AQUA
34549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getColorEffect() {
34569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_EFFECT);
34579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the current color effect setting.
34619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new color effect.
34633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
34649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setColorEffect(String value) {
34669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_EFFECT, value);
34679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported color effects.
34719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34723f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported color effects. null if color effect
34739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
34743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
34759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedColorEffects() {
34779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
34789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
34799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current antibanding setting.
34849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34853f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current antibanding. null if antibanding setting is not
34863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
34873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_AUTO
34883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_50HZ
34893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_60HZ
34903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_OFF
34919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
34929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getAntibanding() {
34939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_ANTIBANDING);
34949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
34959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
34969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
34979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the antibanding.
34989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
34993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param antibanding new antibanding value.
35003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
35019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setAntibanding(String antibanding) {
35039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_ANTIBANDING, antibanding);
35049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported antibanding values.
35089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35093f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported antibanding values. null if antibanding
35103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
35113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
35129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedAntibanding() {
35149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
35159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
35169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current scene mode setting.
35209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return one of SCENE_MODE_XXX string constant. null if scene mode
35229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
35233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_AUTO
35243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_ACTION
35253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PORTRAIT
35263f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_LANDSCAPE
35273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT
35283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT_PORTRAIT
35293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_THEATRE
35303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_BEACH
35313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SNOW
35323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SUNSET
35333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_STEADYPHOTO
35343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_FIREWORKS
35353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SPORTS
35363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PARTY
35373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_CANDLELIGHT
3538da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * @see #SCENE_MODE_BARCODE
35399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getSceneMode() {
35419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_SCENE_MODE);
35429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3545c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Sets the scene mode. Changing scene mode may override other
3546c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * parameters (such as flash mode, focus mode, white balance). For
3547c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * example, suppose originally flash mode is on and supported flash
3548c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * modes are on/off. In night scene mode, both flash mode and supported
3549c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * flash mode may be changed to off. After setting scene mode,
35502988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * applications should call getParameters to know if some parameters are
35512988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * changed.
35529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value scene mode.
35543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
35559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setSceneMode(String value) {
35579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_SCENE_MODE, value);
35589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported scene modes.
35629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported scene modes. null if scene mode setting
35643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
35653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
35669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedSceneModes() {
35689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
35699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
35709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current flash mode setting.
35749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current flash mode. null if flash mode setting is not
35763f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
35773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_OFF
35783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_AUTO
35793f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_ON
35803f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_RED_EYE
35813f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_TORCH
35829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getFlashMode() {
35849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_FLASH_MODE);
35859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the flash mode.
35899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
35903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value flash mode.
35913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
35929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
35939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setFlashMode(String value) {
35949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_FLASH_MODE, value);
35959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
35969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
35979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
35989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported flash modes.
35999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
36003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported flash modes. null if flash mode setting
36013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
36023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
36039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
36049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedFlashModes() {
36059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
36069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
36079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
36089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
360936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
361036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the current focus mode setting.
361136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
3612699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * @return current focus mode. This method will always return a non-null
3613699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         value. Applications should call {@link
3614699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         #autoFocus(AutoFocusCallback)} to start the focus if focus
3615699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
36163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_AUTO
36173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_INFINITY
36183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_MACRO
36193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_FIXED
3620f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * @see #FOCUS_MODE_EDOF
3621d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
362236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
362336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public String getFocusMode() {
362436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return get(KEY_FOCUS_MODE);
362536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
362636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
362736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
362836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Sets the focus mode.
362936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
36303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value focus mode.
36313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
363236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
363336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public void setFocusMode(String value) {
363436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            set(KEY_FOCUS_MODE, value);
363536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
363636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
363736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
363836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the supported focus modes.
363936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
36403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported focus modes. This method will always
36413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
36423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
364336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
364436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public List<String> getSupportedFocusModes() {
364536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
364636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return split(str);
364736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
364836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
364936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
36506c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the focal length (in millimeter) of the camera.
36516c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
3652bb85e1ccb83492d3df9f4ce12d45ba3db1428744Yin-Chia Yeh         * @return the focal length. Returns -1.0 when the device
3653bb85e1ccb83492d3df9f4ce12d45ba3db1428744Yin-Chia Yeh         *         doesn't report focal length information.
36546c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
36556c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getFocalLength() {
36566c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_FOCAL_LENGTH));
36576c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
36586c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
36596c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
36606c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the horizontal angle of view in degrees.
36616c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
3662564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh         * @return horizontal angle of view. Returns -1.0 when the device
3663564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh         *         doesn't report view angle information.
36646c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
36656c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getHorizontalViewAngle() {
36666c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
36676c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
36686c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
36696c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
36706c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the vertical angle of view in degrees.
36716c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
3672564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh         * @return vertical angle of view. Returns -1.0 when the device
3673564ae82230c0a694b5781fe01e2e01bea46a1c18Yin-Chia Yeh         *         doesn't report view angle information.
36746c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
36756c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getVerticalViewAngle() {
36766c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
36776c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
36786c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
36796c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
368024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the current exposure compensation index.
3681ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
368224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return current exposure compensation index. The range is {@link
368324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMinExposureCompensation} to {@link
368424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMaxExposureCompensation}. 0 means exposure is not
368524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         adjusted.
3686ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3687ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public int getExposureCompensation() {
368824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_EXPOSURE_COMPENSATION, 0);
3689ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3690ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3691ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
369224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Sets the exposure compensation index.
3693ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
36940402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         * @param value exposure compensation index. The valid value range is
36950402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         *        from {@link #getMinExposureCompensation} (inclusive) to {@link
369624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        #getMaxExposureCompensation} (inclusive). 0 means exposure is
369724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        not adjusted. Application should call
369824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        getMinExposureCompensation and getMaxExposureCompensation to
369924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        know if exposure compensation is supported.
3700ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3701ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public void setExposureCompensation(int value) {
3702ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li            set(KEY_EXPOSURE_COMPENSATION, value);
3703ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3704ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3705ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
370624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the maximum exposure compensation index.
3707ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
370824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return maximum exposure compensation index (>=0). If both this
370924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMinExposureCompensation} return 0,
371024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
371124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
371224b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMaxExposureCompensation() {
371324b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
371424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
371524b326a8978bf78e3e560723dde221792784325bWu-cheng Li
371624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
371724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the minimum exposure compensation index.
371824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
371924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return minimum exposure compensation index (<=0). If both this
372024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMaxExposureCompensation} return 0,
372124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
3722ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
372324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMinExposureCompensation() {
372424b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
372524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
372624b326a8978bf78e3e560723dde221792784325bWu-cheng Li
372724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
372824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the exposure compensation step.
372924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
373024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return exposure compensation step. Applications can get EV by
373124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         multiplying the exposure compensation index and step. Ex: if
373224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation index is -6 and step is 0.333333333, EV
373324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         is -2.
373424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
373524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public float getExposureCompensationStep() {
373624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
3737ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3738ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3739ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
3740d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-exposure lock state. Applications should check
3741d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method.</p>
37423773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3743d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-exposure routine will immediately
3744d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * pause until the lock is set to false. Exposure compensation settings
3745d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * changes will still take effect while auto-exposure is locked.</p>
3746d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3747d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-exposure is already locked, setting this to true again has
3748d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * no effect (the driver will not recalculate exposure values).</p>
3749d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3750d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3751d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3752b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3753b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock.</p>
3754d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3755b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3756b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock can be used to capture an exposure-bracketed burst of images,
3757b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * for example.</p>
3758d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3759d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Auto-exposure state, including the lock state, will not be
37603773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * maintained after camera {@link #release()} is called.  Locking
37613773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * auto-exposure after {@link #open()} but before the first call to
37623773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #startPreview()} will not allow the auto-exposure routine to
3763d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * run at all, and may result in severely over- or under-exposed
3764d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * images.</p>
37653773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
37663773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @param toggle new state of the auto-exposure lock. True means that
37673773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        auto-exposure is locked, false means that the auto-exposure
37683773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        routine is free to run normally.
37693773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3770d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoExposureLock()
37713773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
37723773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public void setAutoExposureLock(boolean toggle) {
37733773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
37743773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
37753773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
37763773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
37773773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Gets the state of the auto-exposure lock. Applications should check
37783773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method. See
37793773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
37803773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
37813773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return State of the auto-exposure lock. Returns true if
3782b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         auto-exposure is currently locked, and false otherwise.
37833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
37843773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
37853773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
37863773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
37873773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean getAutoExposureLock() {
37883773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK);
37893773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
37903773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
37913773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
37923773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
37933773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Returns true if auto-exposure locking is supported. Applications
37943773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * should call this before trying to lock auto-exposure. See
37953773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
37963773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
37973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return true if auto-exposure lock is supported.
37983773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
37993773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
38003773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
38013773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean isAutoExposureLockSupported() {
38023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
38033773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
38043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
38053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
38063773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
3807d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-white balance lock state. Applications should check
3808d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoWhiteBalanceLockSupported} before using this
3809d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method.</p>
3810d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3811d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-white balance routine will
3812d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * immediately pause until the lock is set to false.</p>
3813d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3814d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-white balance is already locked, setting this to true
3815d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * again has no effect (the driver will not recalculate white balance
3816d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * values).</p>
3817d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3818d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3819d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3820b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3821b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * the lock.</p>
3822d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
382316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * <p> Changing the white balance mode with {@link #setWhiteBalance}
382416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * will release the auto-white balance lock if it is set.</p>
382516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         *
3826b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, AE lock, and AWB lock can be used to
3827b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * capture an exposure-bracketed burst of images, for example.
3828b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Auto-white balance state, including the lock state, will not be
3829b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * maintained after camera {@link #release()} is called.  Locking
3830b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * auto-white balance after {@link #open()} but before the first call to
3831b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * {@link #startPreview()} will not allow the auto-white balance routine
3832b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * to run at all, and may result in severely incorrect color in captured
3833b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * images.</p>
3834d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3835d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @param toggle new state of the auto-white balance lock. True means
3836d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        that auto-white balance is locked, false means that the
3837d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        auto-white balance routine is free to run normally.
3838d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3839d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoWhiteBalanceLock()
384016b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * @see #setWhiteBalance(String)
3841d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3842d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public void setAutoWhiteBalanceLock(boolean toggle) {
3843d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3844d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3845d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3846d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3847d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Gets the state of the auto-white balance lock. Applications should
3848d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * check {@link #isAutoWhiteBalanceLockSupported} before using this
3849d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method. See {@link #setAutoWhiteBalanceLock} for details about the
3850d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * lock.
3851d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3852d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return State of the auto-white balance lock. Returns true if
3853d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *         auto-white balance is currently locked, and false
3854b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         otherwise.
3855d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3856d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3857d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3858d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3859d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean getAutoWhiteBalanceLock() {
3860d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3861d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3862d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3863d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3864d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3865d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Returns true if auto-white balance locking is supported. Applications
3866d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * should call this before trying to lock auto-white balance. See
3867d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #setAutoWhiteBalanceLock} for details about the lock.
3868d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3869d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return true if auto-white balance lock is supported.
3870d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3871d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3872d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3873d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean isAutoWhiteBalanceLockSupported() {
3874d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3875d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3876d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3877d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3878d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
387936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets current zoom value. This also works when smooth zoom is in
38808cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * progress. Applications should check {@link #isZoomSupported} before
38818cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * using this method.
388236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
388336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the current zoom value. The range is 0 to {@link
38848cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom}. 0 means the camera is not zoomed.
388536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
388636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getZoom() {
38878cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_ZOOM, 0);
388836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
388936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
389036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
38918cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Sets current zoom value. If the camera is zoomed (value > 0), the
38928cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * actual picture size may be smaller than picture size setting.
38938cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications can check the actual picture size after picture is
38948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * returned from {@link PictureCallback}. The preview size remains the
38958cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * same in zoom. Applications should check {@link #isZoomSupported}
38968cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * before using this method.
389736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
389836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
389936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
390036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public void setZoom(int value) {
39018cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            set(KEY_ZOOM, value);
390236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
390336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
390436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
390536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if zoom is supported. Applications should call this
390636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * before using other zoom methods.
390736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
390836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if zoom is supported.
390936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
391036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isZoomSupported() {
39118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_ZOOM_SUPPORTED);
39128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
391336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
391436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
391536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
391636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets the maximum zoom value allowed for snapshot. This is the maximum
391736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * value that applications can set to {@link #setZoom(int)}.
39188cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications should call {@link #isZoomSupported} before using this
39198cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * method. This value may change in different preview size. Applications
39208cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * should call this again after setting preview size.
392136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
392236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the maximum zoom value supported by the camera.
392336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
392436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getMaxZoom() {
39258cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_MAX_ZOOM, 0);
392636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
392736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
392836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
39298cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Gets the zoom ratios of all zoom values. Applications should check
39308cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * {@link #isZoomSupported} before using this method.
393136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
39328cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
39338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         returned as 320. The number of elements is {@link
39348cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom} + 1. The list is sorted from small to large. The
39358cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         first element is always 100. The last element is the zoom
39368cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         ratio of the maximum zoom value.
393736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
39388cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        public List<Integer> getZoomRatios() {
39398cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return splitInt(get(KEY_ZOOM_RATIOS));
394036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
394136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
394236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
394336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if smooth zoom is supported. Applications should call
394436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * this before using other smooth zoom methods.
394536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
394636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if smooth zoom is supported.
394736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
394836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isSmoothZoomSupported() {
39498cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
39508cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
395136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
395236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
3953e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
395432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the distances from the camera to where an object appears to be
3955e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * in focus. The object is sharpest at the optimal focus distance. The
395632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * depth of field is the far focus distance minus near focus distance.</p>
3957e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
395832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus distances may change after calling {@link
3959e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3960e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #startPreview()}. Applications can call {@link #getParameters()}
3961e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * and this method anytime to get the latest focus distances. If the
3962d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
396332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * from time to time.</p>
3964699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *
396532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>This method is intended to estimate the distance between the camera
3966699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * and the subject. After autofocus, the subject distance may be within
3967699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * near and far focus distance. However, the precision depends on the
3968699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * camera hardware, autofocus algorithm, the focus area, and the scene.
396932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * The error can be large and it should be only used as a reference.</p>
3970e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
397132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Far focus distance >= optimal focus distance >= near focus distance.
3972185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * If the focus distance is infinity, the value will be
397332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * {@code Float.POSITIVE_INFINITY}.</p>
3974e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
3975e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * @param output focus distances in meters. output must be a float
3976e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        array with three elements. Near focus distance, optimal focus
3977e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        distance, and far focus distance will be filled in the array.
3978185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_NEAR_INDEX
3979185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3980185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_FAR_INDEX
3981e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
3982e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public void getFocusDistances(float[] output) {
3983e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            if (output == null || output.length != 3) {
3984e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                throw new IllegalArgumentException(
3985f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa                        "output must be a float array with three elements.");
3986e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3987454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitFloat(get(KEY_FOCUS_DISTANCES), output);
3988e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3989e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
399030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
399130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Gets the maximum number of focus areas supported. This is the maximum
39927b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * length of the list in {@link #setFocusAreas(List)} and
39937b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getFocusAreas()}.
399430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
399530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return the maximum number of focus areas supported by the camera.
399630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
399730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
399830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int getMaxNumFocusAreas() {
399930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
400030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
400130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
400230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
400332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current focus areas. Camera driver uses the areas to decide
400432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus.</p>
400530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
400632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
40077b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumFocusAreas()} to know the maximum number of
400832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus areas first. If the value is 0, focus area is not supported.</p>
400930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
401032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each focus area is a rectangle with specified weight. The direction
401130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * is relative to the sensor orientation, that is, what the sensor sees.
401230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * The direction is not affected by the rotation or mirroring of
401330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
401430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * range from -1000 to 1000. (-1000, -1000) is the upper left point.
4015bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * (1000, 1000) is the lower right point. The width and height of focus
401632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * areas cannot be 0 or negative.</p>
401730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
401832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000. The weight should be
40194e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * interpreted as a per-pixel weight - all pixels in the area have the
40204e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * specified weight. This means a small area with the same weight as a
40214e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * larger area will have less influence on the focusing than the larger
40224e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * area. Focus areas can partially overlap and the driver will add the
402332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * weights in the overlap region.</p>
402430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
402532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} focus area list means the driver is
402632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * free to select focus targets as it wants. For example, the driver may
402732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * use more signals to select focus areas and change them
402832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * dynamically. Apps can set the focus area list to {@code null} if they
402932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * want the driver to completely control focusing.</p>
403030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
403132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus areas are relative to the current field of view
403230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
403330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * represents the top of the currently visible camera frame. The focus
403430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * area cannot be set to be outside the current field of view, even
403532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * when using zoom.</p>
403630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
403732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus area only has effect if the current focus mode is
403853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
403953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
404053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
404130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
404230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return a list of current focus areas
404330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
404430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public List<Area> getFocusAreas() {
4045f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            return splitArea(get(KEY_FOCUS_AREAS));
404630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
404730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
404830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
404930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Sets focus areas. See {@link #getFocusAreas()} for documentation.
405030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
40517b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param focusAreas the focus areas
405230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
405330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
4054e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setFocusAreas(List<Area> focusAreas) {
4055e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_FOCUS_AREAS, focusAreas);
4056e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
4057e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
4058e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
4059e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Gets the maximum number of metering areas supported. This is the
40607b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * maximum length of the list in {@link #setMeteringAreas(List)} and
40617b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getMeteringAreas()}.
4062e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
4063e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return the maximum number of metering areas supported by the camera.
4064e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
4065e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
4066e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public int getMaxNumMeteringAreas() {
4067e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
4068e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
4069e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
4070e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
407132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current metering areas. Camera driver uses these areas to
407232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * decide exposure.</p>
4073e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
407432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
40757b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
40767b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * metering areas first. If the value is 0, metering area is not
407732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * supported.</p>
4078e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
407932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each metering area is a rectangle with specified weight. The
4080e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * direction is relative to the sensor orientation, that is, what the
4081e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * sensor sees. The direction is not affected by the rotation or
4082e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
4083e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
4084bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * point. (1000, 1000) is the lower right point. The width and height of
408532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * metering areas cannot be 0 or negative.</p>
4086e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
408732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000, and represents a weight for
40884e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * every pixel in the area. This means that a large metering area with
40894e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * the same weight as a smaller area will have more effect in the
40904e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * metering result.  Metering areas can partially overlap and the driver
409132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * will add the weights in the overlap region.</p>
4092e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
409332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} metering area list means the driver
409432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * is free to meter as it chooses. For example, the driver may use more
409532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * signals to select metering areas and change them dynamically. Apps
409632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * can set the metering area list to {@code null} if they want the
409732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * driver to completely control metering.</p>
4098e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
409932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Metering areas are relative to the current field of view
4100e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
4101e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * represents the top of the currently visible camera frame. The
4102e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * metering area cannot be set to be outside the current field of view,
410332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * even when using zoom.</p>
4104e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
410532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>No matter what metering areas are, the final exposure are compensated
410632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * by {@link #setExposureCompensation(int)}.</p>
4107e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
4108e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return a list of current metering areas
4109e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
4110e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public List<Area> getMeteringAreas() {
4111d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li            return splitArea(get(KEY_METERING_AREAS));
4112e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
4113e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
4114e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
4115e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Sets metering areas. See {@link #getMeteringAreas()} for
4116e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * documentation.
4117e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
41187b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param meteringAreas the metering areas
4119e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
4120e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
4121e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setMeteringAreas(List<Area> meteringAreas) {
4122e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_METERING_AREAS, meteringAreas);
412330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
412430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
41254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
41264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Gets the maximum number of detected faces supported. This is the
41274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * maximum length of the list returned from {@link FaceDetectionListener}.
41284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * If the return value is 0, face detection of the specified type is not
41294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * supported.
41304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
41314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * @return the maximum number of detected face supported by the camera.
4132464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
41334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
4134c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        public int getMaxNumDetectedFaces() {
4135c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li            return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
41364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
41374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
413825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        /**
41399c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Sets recording mode hint. This tells the camera that the intent of
41409c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * the application is to record videos {@link
41419c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * android.media.MediaRecorder#start()}, not to take still pictures
41429c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
41439c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
41449c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * allow MediaRecorder.start() to start faster or with fewer glitches on
41459c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * output. This should be called before starting preview for the best
41469c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * result, but can be changed while the preview is active. The default
41479c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * value is false.
41489c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
41499c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * The app can still call takePicture() when the hint is true or call
41509c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * MediaRecorder.start() when the hint is false. But the performance may
41519c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * be worse.
41529c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
41539c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * @param hint true if the apps intend to record videos using
415425d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         *             {@link android.media.MediaRecorder}.
415525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         */
415625d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        public void setRecordingHint(boolean hint) {
415725d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li            set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
415825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        }
415925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li
416098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        /**
41611cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Returns true if video snapshot is supported. That is, applications
416298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * can call {@link #takePicture(Camera.ShutterCallback,
41631cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback, Camera.PictureCallback,
41641cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback)} during recording. Applications do not need
41651cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * to call {@link #startPreview()} after taking a picture. The preview
41661cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * will be still active. Other than that, taking a picture during
41671cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * recording is identical to taking a picture normally. All settings and
41681cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * methods related to takePicture work identically. Ex:
41691cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
41701cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
41711cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
41721cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #FLASH_MODE_ON} also still work, but the video will record the
41731cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * flash.</p>
41741cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         *
41751cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Applications can set shutter callback as null to avoid the shutter
417698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * sound. It is also recommended to set raw picture and post view
41771cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * callbacks to null to avoid the interrupt of preview display.</p>
417898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
41791cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Field-of-view of the recorded video may be different from that of the
41801cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * captured pictures. The maximum size of a video snapshot may be
41811cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * smaller than that for regular still captures. If the current picture
41821cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * size is set higher than can be supported by video snapshot, the
41831cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will be captured at the maximum supported size instead.</p>
418498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
418598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * @return true if video snapshot is supported.
418698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         */
418798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        public boolean isVideoSnapshotSupported() {
418898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
418998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            return TRUE.equals(str);
419098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        }
419198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li
4192037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4193037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Enables and disables video stabilization. Use
4194037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #isVideoStabilizationSupported} to determine if calling this
4195037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * method is valid.</p>
4196037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4197037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization reduces the shaking due to the motion of the
4198037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * camera in both the preview stream and in recorded videos, including
4199037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * data received from the preview callback. It does not reduce motion
4200037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * blur in images captured with
4201037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link Camera#takePicture takePicture}.</p>
4202037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4203037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization can be enabled and disabled while preview or
4204037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * recording is active, but toggling it may cause a jump in the video
4205037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * stream that may be undesirable in a recorded video.</p>
4206037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4207037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @param toggle Set to true to enable video stabilization, and false to
4208037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * disable video stabilization.
4209037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
4210037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
4211037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4212037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public void setVideoStabilization(boolean toggle) {
4213037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
4214037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4215037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
4216037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4217037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Get the current state of video stabilization. See
4218037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
4219037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4220037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is enabled
4221037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
4222037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
4223037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4224037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean getVideoStabilization() {
4225037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION);
4226037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
4227037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4228037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
4229037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
4230037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Returns true if video stabilization is supported. See
4231037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
4232037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
4233037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is supported
4234037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
4235037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
4236037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
4237037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean isVideoStabilizationSupported() {
4238037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
4239037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
4240037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
4241037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
42429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of String.
42439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
42449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<String> split(String str) {
42459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
42469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
42470a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
42480a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
42499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<String> substrings = new ArrayList<String>();
42500a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
42510a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(s);
42529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
42539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
42549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
42559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
42569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Integer.
42579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
42589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Integer> splitInt(String str) {
42599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
42609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
42610a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
42620a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
42639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Integer> substrings = new ArrayList<Integer>();
42640a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
42650a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(Integer.parseInt(s));
42669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
42679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (substrings.size() == 0) return null;
42689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
42699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
42709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4271454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitInt(String str, int[] output) {
4272454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
4273454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
42740a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
42750a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
4276454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
42770a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
42780a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Integer.parseInt(s);
4279454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
4280454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
4281454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4282e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Splits a comma delimited string to an ArrayList of Float.
4283454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitFloat(String str, float[] output) {
4284454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
4285e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
42860a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
42870a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
4288454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
42890a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
42900a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Float.parseFloat(s);
4291e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
4292e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
4293e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
429424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a float parameter.
429524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private float getFloat(String key, float defaultValue) {
429624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
429724b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Float.parseFloat(mMap.get(key));
429824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
429924b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
430024b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
430124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
430224b326a8978bf78e3e560723dde221792784325bWu-cheng Li
430324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a integer parameter.
430424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private int getInt(String key, int defaultValue) {
430524b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
430624b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Integer.parseInt(mMap.get(key));
430724b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
430824b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
430924b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
431024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
431124b326a8978bf78e3e560723dde221792784325bWu-cheng Li
43129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Size.
43139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
43149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Size> splitSize(String str) {
43159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
43169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
43170a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
43180a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
43199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Size> sizeList = new ArrayList<Size>();
43200a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
43210a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                Size size = strToSize(s);
43229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                if (size != null) sizeList.add(size);
43239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
43249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (sizeList.size() == 0) return null;
43259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return sizeList;
43269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
43279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
43289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parses a string (ex: "480x320") to Size object.
43299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null.
43309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private Size strToSize(String str) {
43319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
43329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
43339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            int pos = str.indexOf('x');
43349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (pos != -1) {
43359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String width = str.substring(0, pos);
43369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String height = str.substring(pos + 1);
43379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                return new Size(Integer.parseInt(width),
43389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                                Integer.parseInt(height));
43399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
43409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            Log.e(TAG, "Invalid size parameter string=" + str);
43419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return null;
43429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
4343454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4344454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Splits a comma delimited string to an ArrayList of int array.
4345454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Example string: "(10000,26623),(10000,30000)". Return null if the
4346454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // passing string is null or the size is 0.
4347454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private ArrayList<int[]> splitRange(String str) {
4348454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null || str.charAt(0) != '('
4349454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
4350454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                Log.e(TAG, "Invalid range list string=" + str);
4351454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                return null;
4352454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
4353454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4354454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            ArrayList<int[]> rangeList = new ArrayList<int[]>();
4355454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int endIndex, fromIndex = 1;
4356454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            do {
4357454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                int[] range = new int[2];
4358454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
4359454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
4360454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                splitInt(str.substring(fromIndex, endIndex), range);
4361454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                rangeList.add(range);
4362454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                fromIndex = endIndex + 3;
4363454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            } while (endIndex != str.length() - 1);
4364454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
4365454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (rangeList.size() == 0) return null;
4366454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return rangeList;
4367454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
436830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
436930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Splits a comma delimited string to an ArrayList of Area objects.
437030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
4371f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li        // the passing string is null or the size is 0 or (0,0,0,0,0).
437230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private ArrayList<Area> splitArea(String str) {
437330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (str == null || str.charAt(0) != '('
437430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
437530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Log.e(TAG, "Invalid area string=" + str);
437630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return null;
437730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
437830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
437930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            ArrayList<Area> result = new ArrayList<Area>();
438030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int endIndex, fromIndex = 1;
438130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int[] array = new int[5];
438230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            do {
438330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
438430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
438530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                splitInt(str.substring(fromIndex, endIndex), array);
438630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Rect rect = new Rect(array[0], array[1], array[2], array[3]);
438730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                result.add(new Area(rect, array[4]));
438830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                fromIndex = endIndex + 3;
438930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } while (endIndex != str.length() - 1);
439030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
439130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (result.size() == 0) return null;
4392f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
4393f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (result.size() == 1) {
4394bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li                Area area = result.get(0);
4395f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                Rect rect = area.rect;
4396f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                if (rect.left == 0 && rect.top == 0 && rect.right == 0
4397f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                        && rect.bottom == 0 && area.weight == 0) {
4398f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    return null;
4399f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
4400f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            }
4401f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
440230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return result;
440330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
4404b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li
4405b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        private boolean same(String s1, String s2) {
4406b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 == null && s2 == null) return true;
4407b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 != null && s1.equals(s2)) return true;
4408b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            return false;
4409b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        }
44109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
44119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4412