Camera.java revision a1b02dbb6edf0644720716d3f271b1ee091aa2d6
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.hardware;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvalaimport android.app.ActivityThread;
2010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant;
2110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Liimport android.annotation.SdkConstant.SdkConstantType;
224f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.content.Context;
23a696f5d667227365da732481770767dcb330dd23Mathias Agopianimport android.graphics.ImageFormat;
244c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Liimport android.graphics.Point;
2530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Liimport android.graphics.Rect;
26fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennisimport android.graphics.SurfaceTexture;
274f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.media.IAudioService;
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
294f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.IBinder;
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper;
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message;
324f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.RemoteException;
334f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvalaimport android.os.ServiceManager;
347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Allocation;
357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Element;
367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.RenderScript;
377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.RSIllegalArgumentException;
387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvalaimport android.renderscript.Type;
39bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.util.Log;
400a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selenimport android.text.TextUtils;
41bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.Surface;
42bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport android.view.SurfaceHolder;
43bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li
44bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.io.IOException;
45bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.lang.ref.WeakReference;
46bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.ArrayList;
47bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.HashMap;
48bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.List;
49248ba23ad28c1f8fb69904663204df08c5818700James Dongimport java.util.concurrent.locks.ReentrantLock;
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
52bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The Camera class is used to set image capture settings, start/stop preview,
53bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * snap pictures, and retrieve frames for encoding for video.  This class is a
54bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * client for the Camera service, which manages the actual camera hardware.
55df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
56bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To access the device camera, you must declare the
577478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * {@link android.Manifest.permission#CAMERA} permission in your Android
58df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * Manifest. Also be sure to include the
59df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
60bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * manifest element to declare camera features used by your application.
617478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * For example, if you use the camera and auto-focus feature, your Manifest
62df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * should include the following:</p>
63df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <pre> &lt;uses-permission android:name="android.permission.CAMERA" />
64df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera" />
65df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * &lt;uses-feature android:name="android.hardware.camera.autofocus" /></pre>
66df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main *
67bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To take pictures with this class, use the following steps:</p>
68bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
69bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
70341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * <li>Obtain an instance of Camera from {@link #open(int)}.
71bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
72bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Get existing (default) settings with {@link #getParameters()}.
73bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
74bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If necessary, modify the returned {@link Camera.Parameters} object and call
75bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setParameters(Camera.Parameters)}.
76bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
77bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, call {@link #setDisplayOrientation(int)}.
78bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
79bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
80bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewDisplay(SurfaceHolder)}.  Without a surface, the camera
81bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * will be unable to start the preview.
82bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
83bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important</b>: Call {@link #startPreview()} to start updating the
84bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * preview surface.  Preview must be started before you can take a picture.
85bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
86bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When you want, call {@link #takePicture(Camera.ShutterCallback,
87bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to
88bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * capture a photo.  Wait for the callbacks to provide the actual image data.
89bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
90bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>After taking a picture, preview display will have stopped.  To take more
91bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * photos, call {@link #startPreview()} again first.
92bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
93bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} to stop updating the preview surface.
94bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
95bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li><b>Important:</b> Call {@link #release()} to release the camera for
96bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * use by other applications.  Applications should release the camera
97bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()}
98bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * it in {@link android.app.Activity#onResume()}).
99bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
100bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
101bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>To quickly switch to video recording mode, use these steps:</p>
102bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
103bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <ol>
104bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Obtain and initialize a Camera and start preview as described above.
105bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
106bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #unlock()} to allow the media process to access the camera.
107bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
108bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}.
109bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * See {@link android.media.MediaRecorder} information about video recording.
110bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
111bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>When finished recording, call {@link #reconnect()} to re-acquire
112bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * and re-lock the camera.
113bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
114bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>If desired, restart preview and take more photos or videos.
115bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
116bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <li>Call {@link #stopPreview()} and {@link #release()} as described above.
117bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * </ol>
118bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
119bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This class is not thread-safe, and is meant for use from one event thread.
120bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Most long-running operations (preview, focus, photo capture, etc) happen
121bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * asynchronously and invoke callbacks as necessary.  Callbacks will be invoked
122341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * on the event thread {@link #open(int)} was called from.  This class's methods
123bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * must never be called from multiple threads at once.</p>
124bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor *
125df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <p class="caution"><strong>Caution:</strong> Different Android-powered devices
126df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * may have different hardware specifications, such as megapixel ratings and
127df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * auto-focus capabilities. In order for your application to be compatible with
1287478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * more devices, you should not make assumptions about the device camera
129df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * specifications.</p>
1306c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez *
1316c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <div class="special reference">
1326c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <h3>Developer Guides</h3>
1336c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <p>For more information about using cameras, read the
1346c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p>
1356c5c3c392b8abce93fd2d366f12449c713ed0016Joe Fernandez * </div>
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Camera {
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final String TAG = "Camera";
1399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
140d2c2929c94bec68741b85f4174e11307fb65157fWu-cheng Li    // These match the enums in frameworks/base/include/camera/Camera.h
141da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ERROR            = 0x001;
142da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_SHUTTER          = 0x002;
143da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_FOCUS            = 0x004;
144da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_ZOOM             = 0x008;
145da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_PREVIEW_FRAME    = 0x010;
146da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_VIDEO_FRAME      = 0x020;
147da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_POSTVIEW_FRAME   = 0x040;
148da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_RAW_IMAGE        = 0x080;
149da83f4674a564007baac03db062a289c8158d940Benny Wong    private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100;
1504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200;
151bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li    private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
1529d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private static final int CAMERA_MSG_FOCUS_MOVE       = 0x800;
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private int mNativeContext; // accessed by native methods
1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private EventHandler mEventHandler;
1569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ShutterCallback mShutterCallback;
1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mRawImageCallback;
1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PictureCallback mJpegCallback;
1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private PreviewCallback mPreviewCallback;
1607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private boolean mUsingPreviewAllocation;
161e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    private PictureCallback mPostviewCallback;
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private AutoFocusCallback mAutoFocusCallback;
1639d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private AutoFocusMoveCallback mAutoFocusMoveCallback;
1643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    private OnZoomChangeListener mZoomListener;
1654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private FaceDetectionListener mFaceListener;
1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private ErrorCallback mErrorCallback;
1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private boolean mOneShot;
16894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private boolean mWithBuffer;
1694c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private boolean mFaceDetectionRunning = false;
170f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li    private Object mAutoFocusCallbackLock = new Object();
1719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
17310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new picture is taken by the camera, and the entry of
17410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * the picture has been added to the media store.
17510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the picture.
17610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
17710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
17810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE";
17910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
18010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
18110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * Broadcast Action:  A new video is recorded by the camera, and the entry
18210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * of the video has been added to the media store.
18310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     * {@link android.content.Intent#getData} is URI of the video.
18410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li     */
18510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
18610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO";
18710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li
18810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li    /**
1894c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Hardware face detection. It does not use much CPU.
1904c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
191c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_HW = 0;
1924c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
194c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Software face detection. It uses some CPU.
1954c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
196c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    private static final int CAMERA_FACE_DETECTION_SW = 1;
1974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1984c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
199341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the number of physical cameras available on this device.
200e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
201e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public native static int getNumberOfCameras();
202e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
203e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
204341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * Returns the information about a particular camera.
205b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
206b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
2074f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
2084f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        _getCameraInfo(cameraId, cameraInfo);
2094f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
2104f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        IAudioService audioService = IAudioService.Stub.asInterface(b);
2114f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        try {
2124f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            if (audioService.isCameraSoundForced()) {
2134f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // Only set this when sound is forced; otherwise let native code
2144f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                // decide.
2154f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                cameraInfo.canDisableShutterSound = false;
2164f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
2174f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        } catch (RemoteException e) {
2184f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            Log.e(TAG, "Audio service is unavailable for queries");
2194f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
2204f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
2214f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
222b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
223b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
224b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * Information about a camera
225b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     */
226b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    public static class CameraInfo {
2277836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2287836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is opposite to that of the screen.
2297836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
230b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_BACK = 0;
2317836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li
2327836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        /**
2337836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         * The facing of the camera is the same as that of the screen.
2347836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li         */
235b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        public static final int CAMERA_FACING_FRONT = 1;
236b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
237b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
238464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * The direction that the camera faces. It should be
239b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
240b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2417836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int facing;
242b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
243b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang        /**
24432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The orientation of the camera image. The value is the angle that the
245b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * camera image needs to be rotated clockwise so it shows correctly on
24632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the display in its natural orientation. It should be 0, 90, 180, or 270.</p>
247b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
24832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>For example, suppose a device has a naturally tall screen. The
2492fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * back-facing camera sensor is mounted in landscape. You are looking at
2502fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * the screen. If the top side of the camera sensor is aligned with the
2512fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the screen in natural orientation, the value should be
2522fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * 90. If the top side of a front-facing camera sensor is aligned with
25332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the right of the screen, the value should be 270.</p>
254b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         *
255b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         * @see #setDisplayOrientation(int)
25669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setRotation(int)
25769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPreviewSize(int, int)
25869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setPictureSize(int, int)
25969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * @see Parameters#setJpegThumbnailSize(int, int)
260b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang         */
2617836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li        public int orientation;
262f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala
263f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        /**
264f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>Whether the shutter sound can be disabled.</p>
265f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
266f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>On some devices, the camera shutter sound cannot be turned off
267f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * through {@link #enableShutterSound enableShutterSound}. This field
268f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * can be used to determine whether a call to disable the shutter sound
269f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * will succeed.</p>
270f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         *
271f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * <p>If this field is set to true, then a call of
272f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * {@code enableShutterSound(false)} will be successful. If set to
273f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * false, then that call will fail, and the shutter sound will be played
274f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         * when {@link Camera#takePicture takePicture} is called.</p>
275f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala         */
276f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala        public boolean canDisableShutterSound;
277b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    };
278b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang
279b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang    /**
280a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * Creates a new Camera object to access a particular hardware camera. If
281a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * the same camera is opened by other applications, this will throw a
282a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * RuntimeException.
283a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *
284bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call {@link #release()} when you are done using the camera,
285bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * otherwise it will remain locked and be unavailable to other applications.
286bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
287341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * <p>Your application should only have one Camera object active at a time
288341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * for a particular hardware camera.
289bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
290bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callbacks from other methods are delivered to the event loop of the
291bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * thread which called open().  If this thread has no event loop, then
292bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callbacks are delivered to the main application event loop.  If there
293bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is no main application event loop, callbacks are not delivered.
294bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
295bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p class="caution"><b>Caution:</b> On some devices, this method may
296bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * take a long time to complete.  It is best to call this method from a
297bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * worker thread (possibly using {@link android.os.AsyncTask}) to avoid
298bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * blocking the main application UI thread.
299bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
300341ff13689dfe822b598e626272ac2e80041b482Dan Egnor     * @param cameraId the hardware camera to access, between 0 and
301a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     *     {@link #getNumberOfCameras()}-1.
302bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @return a new Camera object, connected, locked and ready for use.
303a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     * @throws RuntimeException if opening the camera fails (for example, if the
304a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     camera is in use by another process or device policy manager has
305a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li     *     disabled the camera).
306facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li     * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
307e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang     */
308e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    public static Camera open(int cameraId) {
3097bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li        return new Camera(cameraId);
310e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    }
311e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang
312e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang    /**
313a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * Creates a new Camera object to access the first back-facing camera on the
314a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * device. If the device does not have a back-facing camera, this returns
315a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li     * null.
3167836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li     * @see #open(int)
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public static Camera open() {
319a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        int numberOfCameras = getNumberOfCameras();
320a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        CameraInfo cameraInfo = new CameraInfo();
321a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        for (int i = 0; i < numberOfCameras; i++) {
322a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            getCameraInfo(i, cameraInfo);
323a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
3247bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li                return new Camera(i);
325a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li            }
326a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        }
327a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li        return null;
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3307bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li    Camera(int cameraId) {
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = null;
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = null;
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = null;
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = null;
335e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = null;
3367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        mUsingPreviewAllocation = false;
3373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = null;
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Looper looper;
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if ((looper = Looper.myLooper()) != null) {
3419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else if ((looper = Looper.getMainLooper()) != null) {
3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = new EventHandler(this, looper);
3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else {
3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mEventHandler = null;
3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
348788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala        String packageName = ActivityThread.currentPackageName();
349788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala
350788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala        native_setup(new WeakReference<Camera>(this), cameraId, packageName);
3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3531c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
3541c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * An empty Camera for testing purpose.
3551c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
3561c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    Camera() {
3571c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
3581c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
3599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    protected void finalize() {
360e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala        release();
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
363788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala    private native final void native_setup(Object camera_this, int cameraId,
364788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala                                           String packageName);
365788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala
3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_release();
3679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disconnects and releases the Camera object resources.
371bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
372bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>You must call this as soon as you're done with the Camera object.</p>
3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li    public final void release() {
3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_release();
3764c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
380bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unlocks the camera to allow another process to access it.
381bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Normally, the camera is locked to the process with an active Camera
382bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * object until {@link #release()} is called.  To allow rapid handoff
383bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * between processes, you can call this method to release the camera
384bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * temporarily for another process to use; once the other process is done
385bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you can call {@link #reconnect()} to reclaim the camera.
386bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
387bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This must be done before calling
38842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be
38942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * called after recording starts.
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
391bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
393bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be unlocked.
3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
395bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void unlock();
3969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
398bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Re-locks the camera to prevent other processes from accessing it.
399bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera objects are locked by default unless {@link #unlock()} is
400bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called.  Normally {@link #reconnect()} is used instead.
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
40253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
40342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
40442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
40542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
40642419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     *
407bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
408bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
409bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws RuntimeException if the camera cannot be re-locked (for
410bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
412ffe1cf251a4f8469695b8acfa37270684dc1b70cWu-cheng Li    public native final void lock();
4139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
415bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Reconnects to the camera service after another process used it.
416bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * After {@link #unlock()} is called, another process may use the
417bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera; when the process is done, you must reconnect to the camera,
418bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * which will re-acquire the lock and allow you to continue using the
419bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera.
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
42153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Since API level 14, camera is automatically locked for applications in
42242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()}. Applications can use the
42342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * camera (ex: zoom) after recording starts. There is no need to call this
42442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * after recording starts or stops.
425bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
426bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If you are not recording video, you probably do not need this method.
427bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
428bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if a connection cannot be re-established (for
429bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     example, if the camera is still in use by another process).
4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
431bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    public native final void reconnect() throws IOException;
4329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
434bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Sets the {@link Surface} to be used for live preview.
435fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
436fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface can be re-set
437fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * without harm.  Setting a preview surface will un-set any preview surface
438fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * texture that was set via {@link #setPreviewTexture}.
4399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
440bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The {@link SurfaceHolder} must already contain a surface when this
441bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method is called.  If you are using {@link android.view.SurfaceView},
442bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * you will need to register a {@link SurfaceHolder.Callback} with
443bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for
444bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before
445bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling setPreviewDisplay() or starting preview.
446bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
447bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method must be called before {@link #startPreview()}.  The
448bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * one exception is that if the preview surface is not set (or set to null)
449bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * before startPreview() is called, then this method may be called once
450bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * with a non-null parameter to set the preview surface.  (This allows
451bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera setup and surface creation to happen in parallel, saving time.)
452bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * The preview surface may not otherwise change while preview is running.
4539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
454bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param holder containing the Surface on which to place the preview,
455bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to remove the preview surface
456bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @throws IOException if the method fails (for example, if the surface
457bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     is unavailable or unsuitable).
4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {
460b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        if (holder != null) {
461b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li            setPreviewDisplay(holder.getSurface());
462b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        } else {
463b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li            setPreviewDisplay((Surface)null);
464b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li        }
4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
467dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    private native final void setPreviewDisplay(Surface surface) throws IOException;
4689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
470fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Sets the {@link SurfaceTexture} to be used for live preview.
471fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * Either a surface or surface texture is necessary for preview, and
472fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview is necessary to take pictures.  The same surface texture can be
473fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * re-set without harm.  Setting a preview surface texture will un-set any
474fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * preview surface that was set via {@link #setPreviewDisplay}.
475fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
476fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * <p>This method must be called before {@link #startPreview()}.  The
477fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * one exception is that if the preview surface texture is not set (or set
478fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * to null) before startPreview() is called, then this method may be called
479fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * once with a non-null parameter to set the preview surface.  (This allows
480fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * camera setup and surface creation to happen in parallel, saving time.)
481fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * The preview surface texture may not otherwise change while preview is
482fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * running.
483fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *
48432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a
485e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * SurfaceTexture set as the preview texture have an unspecified zero point,
486e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * and cannot be directly compared between different cameras or different
487e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * instances of the same camera, or across multiple runs of the same
488e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     * program.
489e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala     *
490108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
491108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
492108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
493108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
494108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
495108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.graphics.SurfaceTexture
496108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.view.TextureView
497fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @param surfaceTexture the {@link SurfaceTexture} to which the preview
498fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     images are to be sent or null to remove the current preview surface
499fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture
500fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     * @throws IOException if the method fails (for example, if the surface
501fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     *     texture is unavailable or unsuitable).
502fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis     */
503dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten    public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException;
504fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis
505fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis    /**
506bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to deliver copies of preview frames as
507bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * they are displayed.
508bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
509bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallback(Camera.PreviewCallback)
510bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setOneShotPreviewCallback(Camera.PreviewCallback)
511bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
512bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startPreview()
5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PreviewCallback
5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
517bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as preview frames are displayed.  This callback is invoked
518341ff13689dfe822b598e626272ac2e80041b482Dan Egnor         * on the event thread {@link #open(int)} was called from.
5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
520951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>If using the {@link android.graphics.ImageFormat#YV12} format,
521951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * refer to the equations in {@link Camera.Parameters#setPreviewFormat}
522951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * for the arrangement of the pixel data in the preview callback
523951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * buffers.
524951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
525bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param data the contents of the preview frame in the format defined
526a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *  by {@link android.graphics.ImageFormat}, which can be queried
527df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         *  with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
528da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         *  If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
5299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             is never called, the default will be the YCbCr_420_SP
5309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *             (NV21) format.
531bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * @param camera the Camera service object.
5329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPreviewFrame(byte[] data, Camera camera);
5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
5359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
537bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts capturing and drawing preview frames to the screen.
538c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * Preview will not actually start until a surface is supplied
539c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * with {@link #setPreviewDisplay(SurfaceHolder)} or
540c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala     * {@link #setPreviewTexture(SurfaceTexture)}.
541bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
542bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},
543bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or
544bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were
545bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}
546bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * will be called when preview data becomes available.
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final void startPreview();
5499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
551bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops capturing and drawing preview frames to the surface, and
552bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * resets the camera for a future call to {@link #startPreview()}.
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopPreview() {
5554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopPreview();
5564c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
557664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang
558664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mShutterCallback = null;
559664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mRawImageCallback = null;
560664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mPostviewCallback = null;
561664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang        mJpegCallback = null;
562f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
563f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li            mAutoFocusCallback = null;
564f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        }
5659d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = null;
5664c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
5674c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
5684c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopPreview();
5699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return current preview state.
5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * FIXME: Unhide before release
5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide
5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public native final boolean previewEnabled();
5779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
5789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
579108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame in addition
580bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to displaying them on the screen.  The callback will be repeatedly called
581bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * for as long as preview is active.  This method can be called at any time,
582108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * even while preview is live.  Any other preview callbacks are
583108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * overridden.</p>
584108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
585108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
586108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
587108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
589bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of each preview frame,
590bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
591108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setPreviewCallback(PreviewCallback cb) {
5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mPreviewCallback = cb;
5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mOneShot = false;
59694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
5977005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
5987005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
5997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
600a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // Always use one-shot mode. We fake camera preview mode by
601a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks        // doing one-shot preview continuously.
60294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
606108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for the next preview frame in
607108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * addition to displaying it on the screen.  After one invocation, the
608108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * callback is cleared. This method can be called any time, even when
609108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview is live.  Any other preview callbacks are overridden.</p>
610108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
611108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
612108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
613108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
615bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the next preview frame,
616bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks.
617108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setOneShotPreviewCallback(PreviewCallback cb) {
62094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
62194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = true;
62294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = false;
6237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
6247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
6257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
62694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, false);
62794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    }
62894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
62994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
63094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp
63194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
632108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>Installs a callback to be invoked for every preview frame, using
633108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to
634bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * displaying them on the screen.  The callback will be repeatedly called
635108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * for as long as preview is active and buffers are available.  Any other
636108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * preview callbacks are overridden.</p>
63794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
638bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>The purpose of this method is to improve preview efficiency and frame
639bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * rate by allowing preview frame memory reuse.  You must call
640bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #addCallbackBuffer(byte[])} at some point -- before or after
641108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * calling this method -- or no callbacks will received.</p>
64294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
643108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>The buffer queue will be cleared if this method is called with a null
644bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called,
645108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is
646108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * called.</p>
647108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
648108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
649108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
650108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
65194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
652bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb a callback object that receives a copy of the preview frame,
653bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *     or null to stop receiving callbacks and clear the buffer queue.
654bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #addCallbackBuffer(byte[])
655108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
65694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
65794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    public final void setPreviewCallbackWithBuffer(PreviewCallback cb) {
65894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mPreviewCallback = cb;
65994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mOneShot = false;
66094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        mWithBuffer = true;
6617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (cb != null) {
6627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            mUsingPreviewAllocation = false;
6637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
66494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp        setHasPreviewCallback(cb != null, true);
6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
66794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp    /**
6683f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Adds a pre-allocated buffer to the preview callback buffer queue.
6693f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Applications can add one or more buffers to the queue. When a preview
670bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * frame arrives and there is still at least one available buffer, the
671bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * buffer will be used and removed from the queue. Then preview callback is
672bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * invoked with the buffer. If a frame arrives and there is no buffer left,
673bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the frame is discarded. Applications should add buffers back when they
674bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * finish processing the data in them.
675c10275abd6a494c93a025f683dde104a5d4f2793Wu-cheng Li     *
676951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>For formats besides YV12, the size of the buffer is determined by
677951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * multiplying the preview image width, height, and bytes per pixel. The
678951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * width and height can be read from
679951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be
680951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} /
681951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * 8, using the image format from
682951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#getPreviewFormat()}.
683951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *
684951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the
685951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * size can be calculated using the equations listed in
686951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * {@link Camera.Parameters#setPreviewFormat}.
68794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
688bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only necessary when
689e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When
690bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setPreviewCallback(PreviewCallback)} or
691bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers
692e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * are automatically allocated. When a supplied buffer is too small to
693e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * hold the preview frame data, preview callback will return null and
694e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * the buffer will be removed from the buffer queue.
69594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     *
696951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     * @param callbackBuffer the buffer to add to the queue. The size of the
697951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala     *   buffer must match the values described above.
6985b9bcda3a26e9b1f9b1eff28a2be8853d69614f0Wu-cheng Li     * @see #setPreviewCallbackWithBuffer(PreviewCallback)
69994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp     */
700e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addCallbackBuffer(byte[] callbackBuffer)
701e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
702e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME);
703e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
704e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
705e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    /**
706e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Adds a pre-allocated buffer to the raw image callback buffer queue.
707e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Applications can add one or more buffers to the queue. When a raw image
708e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * frame arrives and there is still at least one available buffer, the
709e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * buffer will be used to hold the raw image data and removed from the
710e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * queue. Then raw image callback is invoked with the buffer. If a raw
711e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * image frame arrives but there is no buffer left, the frame is
712e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * discarded. Applications should add buffers back when they finish
713e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * processing the data in them by calling this method again in order
714e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * to avoid running out of raw image callback buffers.
715e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
716e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>The size of the buffer is determined by multiplying the raw image
717e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * width, height, and bytes per pixel. The width and height can be
718e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
719e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * can be computed from
720e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
721e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * using the image format from {@link Camera.Parameters#getPreviewFormat()}.
722e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
723e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * <p>This method is only necessary when the PictureCallbck for raw image
724e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * is used while calling {@link #takePicture(Camera.ShutterCallback,
725e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
726e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
72732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Please note that by calling this method, the mode for
72832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * application-managed callback buffers is triggered. If this method has
72932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * never been called, null will be returned by the raw image callback since
73032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * there is no image callback buffer available. Furthermore, When a supplied
73132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * buffer is too small to hold the raw image data, raw image callback will
73232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * return null and the buffer will be removed from the buffer queue.
733e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
734e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @param callbackBuffer the buffer to add to the raw image callback buffer
735e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     queue. The size should be width * height * (bits per pixel) / 8. An
736e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *     null callbackBuffer will be ignored and won't be added to the queue.
737e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
738e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * @see #takePicture(Camera.ShutterCallback,
739e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
740e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     *
741e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * {@hide}
742e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     */
743e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    public final void addRawImageCallbackBuffer(byte[] callbackBuffer)
744e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
745e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE);
746e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
747e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
748e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private final void addCallbackBuffer(byte[] callbackBuffer, int msgType)
749e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    {
750e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // CAMERA_MSG_VIDEO_FRAME may be allowed in the future.
751e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (msgType != CAMERA_MSG_PREVIEW_FRAME &&
752e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType != CAMERA_MSG_RAW_IMAGE) {
753e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            throw new IllegalArgumentException(
754e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                            "Unsupported message type: " + msgType);
755e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
756e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
757e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        _addCallbackBuffer(callbackBuffer, msgType);
758e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    }
759e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
760e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void _addCallbackBuffer(
761e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong                                byte[] callbackBuffer, int msgType);
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
7647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Create a {@link android.renderscript RenderScript}
7657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation Allocation} to use as a
7667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * destination of preview callback frames. Use
7677005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use
7687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the created Allocation as a destination for camera preview frames.</p>
7697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
7707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>The Allocation will be created with a YUV type, and its contents must
7717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * be accessed within Renderscript with the {@code rsGetElementAtYuv_*}
7727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * accessor methods. Its size will be based on the current
7737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#getPreviewSize preview size} configured for this
7747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * camera.</p>
7757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
7767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param rs the RenderScript context for this Allocation.
7777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param usage additional usage flags to set for the Allocation. The usage
7787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always
7797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   be set on the created Allocation, but additional flags may be provided
7807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   here.
7817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @return a new YUV-type Allocation with dimensions equal to the current
7827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview size.
7837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws RSIllegalArgumentException if the usage flags are not compatible
7847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   with an YUV Allocation.
7857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackAllocation
7867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
7877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
7887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final Allocation createPreviewAllocation(RenderScript rs, int usage)
7897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws RSIllegalArgumentException {
7907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Parameters p = getParameters();
7917005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Size previewSize = p.getPreviewSize();
7927005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Type.Builder yuvBuilder = new Type.Builder(rs,
7937005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                Element.createPixel(rs,
7947005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataType.UNSIGNED_8,
7957005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        Element.DataKind.PIXEL_YUV));
7967005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // Use YV12 for wide compatibility. Changing this requires also
7977005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // adjusting camera service's format selection.
7987005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setYuvFormat(ImageFormat.YV12);
7997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setX(previewSize.width);
8007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        yuvBuilder.setY(previewSize.height);
8017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
8027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Allocation a = Allocation.createTyped(rs, yuvBuilder.create(),
8037005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                usage | Allocation.USAGE_IO_INPUT);
8047005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
8057005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        return a;
8067005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
8077005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
8087005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    /**
8097005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Set an {@link android.renderscript.Allocation Allocation} as the
8107005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * target of preview callback data. Use this method for efficient processing
8117005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * of camera preview data with RenderScript. The Allocation must be created
8127005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * with the {@link #createPreviewAllocation createPreviewAllocation }
8137005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * method.</p>
8147005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8157005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Setting a preview allocation will disable any active preview callbacks
8167005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * set by {@link #setPreviewCallback setPreviewCallback} or
8177005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and
8187005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * vice versa. Using a preview allocation still requires an active standard
8197005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview target to be set, either with
8207005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewTexture setPreviewTexture} or
8217005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #setPreviewDisplay setPreviewDisplay}.</p>
8227005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To be notified when new frames are available to the Allocation, use
8247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To
8257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * update the frame currently accessible from the Allocation to the latest
8267005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview frame, call
8277005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p>
8287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>To disable preview into the Allocation, call this method with a
8307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@code null} parameter.</p>
8317005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8327005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>Once a preview allocation is set, the preview size set by
8337005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If
8347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * you wish to change the preview size, first remove the preview allocation
8357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * by calling {@code setPreviewCallbackAllocation(null)}, then change the
8367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * preview size, create a new preview Allocation with
8377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * {@link #createPreviewAllocation createPreviewAllocation}, and set it as
8387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * the new preview callback allocation target.</p>
8397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * <p>If you are using the preview data to create video or still images,
8417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * strongly consider using {@link android.media.MediaActionSound} to
8427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * properly indicate image capture or recording start/stop to the user.</p>
8437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *
8447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @param previewAllocation the allocation to use as destination for preview
8457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IOException if configuring the camera to use the Allocation for
8467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   preview fails.
8477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @throws IllegalArgumentException if the Allocation's dimensions or other
8487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     *   parameters don't meet the requirements.
8497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #createPreviewAllocation
8507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallback
8517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @see #setPreviewCallbackWithBuffer
8527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     * @hide
8537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala     */
8547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    public final void setPreviewCallbackAllocation(Allocation previewAllocation)
8557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            throws IOException {
8567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        Surface previewSurface = null;
8577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (previewAllocation != null) {
8587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Parameters p = getParameters();
8597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             Size previewSize = p.getPreviewSize();
8607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewSize.width != previewAllocation.getType().getX() ||
8617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height != previewAllocation.getType().getY()) {
8627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
8637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation dimensions don't match preview dimensions: " +
8647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is " +
8657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getX() +
8667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ", " +
8677005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewAllocation.getType().getY() +
8687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     ". Preview is " + previewSize.width + ", " +
8697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     previewSize.height);
8707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
8717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if ((previewAllocation.getUsage() &
8727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                             Allocation.USAGE_IO_INPUT) == 0) {
8737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
8747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation usage does not include USAGE_IO_INPUT");
8757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
8767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             if (previewAllocation.getType().getElement().getDataKind() !=
8777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     Element.DataKind.PIXEL_YUV) {
8787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                 throw new IllegalArgumentException(
8797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                     "Allocation is not of a YUV type");
8807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             }
8817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             previewSurface = previewAllocation.getSurface();
8827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = true;
8837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         } else {
8847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala             mUsingPreviewAllocation = false;
8857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         }
8867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala         setPreviewCallbackSurface(previewSurface);
8877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    }
8887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
8897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala    private native final void setPreviewCallbackSurface(Surface s);
8907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private class EventHandler extends Handler
8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Camera mCamera;
8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public EventHandler(Camera c, Looper looper) {
8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            super(looper);
8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mCamera = c;
8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
8999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        @Override
9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void handleMessage(Message msg) {
9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(msg.what) {
903c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_SHUTTER:
9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (mShutterCallback != null) {
9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mShutterCallback.onShutter();
9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
908c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks
909c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_RAW_IMAGE:
910e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mRawImageCallback != null) {
9119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
912e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
9139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
915c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_COMPRESSED_IMAGE:
916e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mJpegCallback != null) {
9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
918e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
9199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
921c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_PREVIEW_FRAME:
922ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                PreviewCallback pCb = mPreviewCallback;
923ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                if (pCb != null) {
9249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    if (mOneShot) {
925a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Clear the callback variable before the callback
926a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // in case the app calls setPreviewCallback from
927a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the callback function
9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        mPreviewCallback = null;
92994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                    } else if (!mWithBuffer) {
930a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // We're faking the camera preview mode to prevent
931a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // the app from being flooded with preview frames.
932a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks                        // Set to oneshot mode again.
93394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp                        setHasPreviewCallback(true, false);
9349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    }
935ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala                    pCb.onPreviewFrame((byte[])msg.obj, mCamera);
9369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
9379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
939e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_POSTVIEW_FRAME:
940e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mPostviewCallback != null) {
941e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                    mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
942e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
943e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
944e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
945c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_FOCUS:
946f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                AutoFocusCallback cb = null;
947f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                synchronized (mAutoFocusCallbackLock) {
948f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb = mAutoFocusCallback;
949f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                }
950f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                if (cb != null) {
951f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    boolean success = msg.arg1 == 0 ? false : true;
952f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li                    cb.onAutoFocus(success, mCamera);
953e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
954e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                return;
955e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
956e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            case CAMERA_MSG_ZOOM:
9573f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                if (mZoomListener != null) {
9583f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li                    mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera);
959e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
962bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li            case CAMERA_MSG_PREVIEW_METADATA:
9634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                if (mFaceListener != null) {
964f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li                    mFaceListener.onFaceDetection((Face[])msg.obj, mCamera);
9654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                }
9664c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li                return;
9674c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
968c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks            case CAMERA_MSG_ERROR :
9699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Error " + msg.arg1);
970e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                if (mErrorCallback != null) {
9719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    mErrorCallback.onError(msg.arg1, mCamera);
972e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks                }
9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9759d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li            case CAMERA_MSG_FOCUS_MOVE:
9769d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                if (mAutoFocusMoveCallback != null) {
9779d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                    mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera);
9789d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                }
9799d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li                return;
9809d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            default:
9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "Unknown message type " + msg.what);
9839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
9859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
9869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static void postEventFromNative(Object camera_ref,
9899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                                            int what, int arg1, int arg2, Object obj)
9909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
9919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Camera c = (Camera)((WeakReference)camera_ref).get();
9929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c == null)
9939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return;
9949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (c.mEventHandler != null) {
9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj);
9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            c.mEventHandler.sendMessage(m);
9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
9999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1002bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to notify on completion of camera auto focus.
1003bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
10047478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * <p>Devices that do not support auto-focus will receive a "fake"
10057478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * callback to this interface. If your application needs auto-focus and
1006df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * should not be installed on devices <em>without</em> auto-focus, you must
1007df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * declare that your app uses the
10087478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * {@code android.hardware.camera.autofocus} feature, in the
1009df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1010df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1011bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1012bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(AutoFocusCallback)
10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
10149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface AutoFocusCallback
10159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
10169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
101769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * Called when the camera auto focus completes.  If the camera
101869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * does not support auto-focus and autoFocus is called,
101969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * onAutoFocus will be called immediately with a fake value of
102069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <code>success</code> set to <code>true</code>.
10219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
1022b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * The auto-focus routine does not lock auto-exposure and auto-white
1023b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * balance after it completes.
102483d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         *
10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param success true if focus was successful, false if otherwise
10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
102783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
102883d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
10309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onAutoFocus(boolean success, Camera camera);
103153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li    }
10329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1034bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Starts camera auto-focus and registers a callback function to run when
1035bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * the camera is focused.  This method is only valid when preview is active
1036bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * (between {@link #startPreview()} and before {@link #stopPreview()}).
1037bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1038bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>Callers should check
1039bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if
1040bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this method should be called. If the camera does not support auto-focus,
1041bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)}
104236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li     * callback will be called immediately.
1043bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1044da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main     * <p>If your application should not be installed
10457478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * on devices without auto-focus, you must declare that your application
10467478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     * uses auto-focus with the
1047df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">&lt;uses-feature></a>
1048df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main     * manifest element.</p>
1049bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1050068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * <p>If the current flash mode is not
1051068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li     * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be
1052bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * fired during auto-focus, depending on the driver and camera hardware.<p>
10537478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li     *
105453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()}
1055b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()}
1056b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * do not change during and after autofocus. But auto-focus routine may stop
1057b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li     * auto-exposure and auto-white balance transiently during focusing.
105883d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     *
105953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * <p>Stopping preview with {@link #stopPreview()}, or triggering still
106053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * image capture with {@link #takePicture(Camera.ShutterCallback,
106153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
106253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * the focus position. Applications must call cancelAutoFocus to reset the
106353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     * focus.</p>
106453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1065108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * <p>If autofocus is successful, consider using
1066108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * {@link android.media.MediaActionSound} to properly play back an autofocus
1067108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * success sound to the user.</p>
1068108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     *
10699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param cb the callback to run
1070bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #cancelAutoFocus()
107183d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean)
107283d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala     * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean)
1073108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala     * @see android.media.MediaActionSound
10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
10759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void autoFocus(AutoFocusCallback cb)
10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
1077f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1078248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = cb;
1079248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1080f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_autoFocus();
10819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_autoFocus();
10839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
10849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1085bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Cancels any auto-focus function in progress.
1086bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Whether or not auto-focus is currently in progress,
1087bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * this function will return the focus position to the default.
1088244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     * If the camera does not support auto-focus, this is a no-op.
1089bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1090bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #autoFocus(Camera.AutoFocusCallback)
1091244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang     */
1092244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    public final void cancelAutoFocus()
1093244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    {
1094f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        synchronized (mAutoFocusCallbackLock) {
1095248ba23ad28c1f8fb69904663204df08c5818700James Dong            mAutoFocusCallback = null;
1096248ba23ad28c1f8fb69904663204df08c5818700James Dong        }
1097f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        native_cancelAutoFocus();
1098f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // CAMERA_MSG_FOCUS should be removed here because the following
1099f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // scenario can happen:
1100f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - An application uses the same thread for autoFocus, cancelAutoFocus
1101f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   and looper thread.
1102f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application calls autoFocus.
1103f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue.
1104f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   Before event handler's handleMessage() is invoked, the application
1105f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   calls cancelAutoFocus and autoFocus.
1106f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus
1107f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //   has been completed. But in fact it is not.
1108f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        //
1109f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // As documented in the beginning of the file, apps should not use
1110f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // multiple threads to call autoFocus and cancelAutoFocus at the same
1111f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS
1112f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        // message after native_cancelAutoFocus is called.
1113f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li        mEventHandler.removeMessages(CAMERA_MSG_FOCUS);
1114244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    }
1115244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    private native final void native_cancelAutoFocus();
1116244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang
1117244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang    /**
11189d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Callback interface used to notify on auto focus start and stop.
11199d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
11206574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * <p>This is only supported in continuous autofocus modes -- {@link
11216574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link
11226574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show
11236574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li     * autofocus animation based on this.</p>
11249d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
11259d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public interface AutoFocusMoveCallback
11269d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    {
11279d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        /**
11289d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * Called when the camera auto focus starts or stops.
11299d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         *
11309d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         * @param start true if focus starts to move, false if focus stops to move
11316574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li         * @param camera the Camera service object
11329d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li         */
11339d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        void onAutoFocusMoving(boolean start, Camera camera);
11349d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
11359d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
11369d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
11379d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * Sets camera auto-focus move callback.
11389d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     *
11399d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     * @param cb the callback to run
11409d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li     */
11419d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) {
11429d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        mAutoFocusMoveCallback = cb;
11439d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li        enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0);
11449d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    }
11459d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
11469d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    private native void enableFocusMoveCallback(int enable);
11479d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li
11489d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li    /**
1149bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to signal the moment of actual image capture.
1150bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1151bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
11529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
11539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ShutterCallback
11549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
11559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1156bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called as near as possible to the moment when a photo is captured
1157bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * from the sensor.  This is a good opportunity to play a shutter sound
1158bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * or give other feedback of camera operation.  This may be some time
1159bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * after the photo was triggered, but some time before the actual data
1160bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * is available.
11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
11629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onShutter();
11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1166bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface used to supply image data from a photo capture.
1167bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1168bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
11699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
11709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface PictureCallback {
11719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
1172bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when image data is available after a picture is taken.
1173bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * The format of the data depends on the context of the callback
1174bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * and {@link Camera.Parameters} settings.
11759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
11769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param data   a byte array of the picture data
11779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera the Camera service object
11789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
11799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onPictureTaken(byte[] data, Camera camera);
11809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
11819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
11829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1183bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Equivalent to takePicture(shutter, raw, null, jpeg).
11849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
1185bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)
11869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
11879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
11889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            PictureCallback jpeg) {
1189e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        takePicture(shutter, raw, null, jpeg);
1190e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
1191e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong    private native final void native_takePicture(int msgType);
1192e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1193e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
11949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * Triggers an asynchronous image capture. The camera service will initiate
11959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * a series of callbacks to the application as the image capture progresses.
11969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The shutter callback occurs after the image is captured. This can be used
11979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * to trigger a sound to let the user know that image has been captured. The
11989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * raw callback occurs when the raw image data is available (NOTE: the data
1199e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * will be null if there is no raw image callback buffer available or the
1200e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong     * raw image callback buffer is not large enough to hold the raw image).
12019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * The postview callback occurs when a scaled, fully processed postview
12029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * image is available (NOTE: not all hardware supports this). The jpeg
12039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * callback occurs when the compressed image is available. If the
12049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * application does not need a particular callback, a null can be passed
12059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * instead of a callback method.
1206e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     *
1207bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>This method is only valid when preview is active (after
1208bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link #startPreview()}).  Preview will be stopped after the image is
1209bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * taken; callers must call {@link #startPreview()} again if they want to
121042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * re-start preview or take more pictures. This should not be called between
121142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#start()} and
121242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li     * {@link android.media.MediaRecorder#stop()}.
121340057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1214bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * <p>After calling this method, you must not call {@link #startPreview()}
1215bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * or take another picture until the JPEG callback has returned.
121640057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li     *
1217bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param shutter   the callback for image capture moment, or null
1218bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param raw       the callback for raw (uncompressed) image data, or null
1219e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     * @param postview  callback with postview image data, may be null
1220bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param jpeg      the callback for JPEG image data, or null
1221e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
1222e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    public final void takePicture(ShutterCallback shutter, PictureCallback raw,
1223e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks            PictureCallback postview, PictureCallback jpeg) {
12249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mShutterCallback = shutter;
12259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mRawImageCallback = raw;
1226e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        mPostviewCallback = postview;
12279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mJpegCallback = jpeg;
1228e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1229e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        // If callback is not set, do not send me callbacks.
1230e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        int msgType = 0;
1231e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mShutterCallback != null) {
1232e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_SHUTTER;
1233e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1234e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mRawImageCallback != null) {
1235e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_RAW_IMAGE;
1236e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1237e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mPostviewCallback != null) {
1238e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_POSTVIEW_FRAME;
1239e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1240e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        if (mJpegCallback != null) {
1241e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong            msgType |= CAMERA_MSG_COMPRESSED_IMAGE;
1242e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        }
1243e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong
1244e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong        native_takePicture(msgType);
1245e9c6c9ccfde7a642a4c0554e2d066f3dbbea98ceWu-cheng Li        mFaceDetectionRunning = false;
12469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
12479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1248e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
1249bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Zooms to the requested value smoothly. The driver will notify {@link
12503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} of the zoom value and whether zoom is stopped at
12513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * the time. For example, suppose the current zoom is 0 and startSmoothZoom
1252bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with value 3. The
1253bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)}
1254bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * method will be called three times with zoom values 1, 2, and 3.
1255bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier.
1256bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Applications should not call startSmoothZoom again or change the zoom
1257bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * value before zoom stops. If the supplied zoom value equals to the current
1258bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * zoom value, no zoom callback will be generated. This method is supported
1259bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported}
1260bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * returns true.
126136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *
126236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * @param value zoom value. The valid range is 0 to {@link
126336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     *              android.hardware.Camera.Parameters#getMaxZoom}.
12640ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws IllegalArgumentException if the zoom value is invalid.
12650ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
1266bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
126736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
126836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void startSmoothZoom(int value);
126936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
127036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
1271bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Stops the smooth zoom. Applications should wait for the {@link
12723f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * OnZoomChangeListener} to know when the zoom is actually stopped. This
12733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * method is supported if {@link
12748cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true.
12750ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     *
12760ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li     * @throws RuntimeException if the method fails.
127736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     */
127836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    public native final void stopSmoothZoom();
127936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
128036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li    /**
12812fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * Set the clockwise rotation of preview display in degrees. This affects
12822fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * the preview frames and the picture displayed after snapshot. This method
12832fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * is useful for portrait mode applications. Note that preview display of
1284b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * front-facing cameras is flipped horizontally before the rotation, that
1285b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * is, the image is reflected along the central vertical axis of the camera
1286b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li     * sensor. So the users can see themselves as looking into a mirror.
1287d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
128869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>This does not affect the order of byte array passed in {@link
12892fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This
12902fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * method is not allowed to be called during preview.
1291d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     *
129269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * <p>If you want to make the camera image show in the same orientation as
129369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick     * the display, you can use the following code.
1294b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * <pre>
1295724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * public static void setCameraDisplayOrientation(Activity activity,
1296724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         int cameraId, android.hardware.Camera camera) {
1297724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.CameraInfo info =
1298724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             new android.hardware.Camera.CameraInfo();
1299724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     android.hardware.Camera.getCameraInfo(cameraId, info);
1300724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int rotation = activity.getWindowManager().getDefaultDisplay()
1301724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *             .getRotation();
1302724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     int degrees = 0;
1303724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     switch (rotation) {
1304724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_0: degrees = 0; break;
1305724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_90: degrees = 90; break;
1306724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_180: degrees = 180; break;
1307724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *         case Surface.ROTATION_270: degrees = 270; break;
1308724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     }
1309b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     *
13102fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     int result;
13112fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
13122fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation + degrees) % 360;
13132fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (360 - result) % 360;  // compensate the mirror
13142fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     } else {  // back-facing
13152fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *         result = (info.orientation - degrees + 360) % 360;
13162fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     *     }
1317724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     *     camera.setDisplayOrientation(result);
1318724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang     * }
1319b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang     * </pre>
1320d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1321d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * <p>Starting from API level 14, this method can be called when preview is
1322d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     * active.
1323d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li     *
1324d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     * @param degrees the angle that the picture will be rotated clockwise.
1325e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                Valid values are 0, 90, 180, and 270. The starting
1326e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang     *                position is 0 (landscape).
13272fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li     * @see #setPreviewDisplay(SurfaceHolder)
1328d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang     */
1329d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    public native final void setDisplayOrientation(int degrees);
1330d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang
1331d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang    /**
1332487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Enable or disable the default shutter sound when taking a picture.</p>
133369fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1334487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>By default, the camera plays the system-defined camera shutter sound
1335487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * when {@link #takePicture} is called. Using this method, the shutter sound
1336487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be disabled. It is strongly recommended that an alternative shutter
1337487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is played in the {@link ShutterCallback} when the system shutter
1338487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound is disabled.</p>
133969fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
1340487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * <p>Note that devices may not always allow disabling the camera shutter
1341487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * sound. If the shutter sound state cannot be set to the desired value,
1342487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * this method will return false. {@link CameraInfo#canDisableShutterSound}
1343487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * can be used to determine whether the device will allow the shutter sound
1344487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * to be disabled.</p>
134569fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *
134669fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @param enabled whether the camera should play the system shutter sound
134769fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     *                when {@link #takePicture takePicture} is called.
1348487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @return {@code true} if the shutter sound state was successfully
1349487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code false} if the shutter sound state could not be
1350487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         changed. {@code true} is also returned if shutter sound playback
1351487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     *         is already set to the requested state.
135269fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see #takePicture
1353487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala     * @see CameraInfo#canDisableShutterSound
135469fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     * @see ShutterCallback
135569fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala     */
13564f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    public final boolean enableShutterSound(boolean enabled) {
13574f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        if (!enabled) {
13584f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
13594f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            IAudioService audioService = IAudioService.Stub.asInterface(b);
13604f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            try {
13614f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                if (audioService.isCameraSoundForced()) return false;
13624f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            } catch (RemoteException e) {
13634f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala                Log.e(TAG, "Audio service is unavailable for queries");
13644f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala            }
13654f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        }
13664f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala        return _enableShutterSound(enabled);
13674f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    }
13684f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala
13694f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala    private native final boolean _enableShutterSound(boolean enabled);
137069fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala
137169fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala    /**
1372bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for zoom changes during a smooth zoom operation.
1373bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1374bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setZoomChangeListener(OnZoomChangeListener)
1375bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #startSmoothZoom(int)
1376e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
13773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public interface OnZoomChangeListener
1378e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
1379e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks        /**
1380bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor         * Called when the zoom value has changed during a smooth zoom.
138136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
138236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param zoomValue the current zoom value. In smooth zoom mode, camera
13833f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *                  calls this for every new zoom value.
138436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param stopped whether smooth zoom is stopped. If the value is true,
138536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *                this is the last zoom update for the application.
1386e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         * @param camera  the Camera service object
1387e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks         */
13883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        void onZoomChange(int zoomValue, boolean stopped, Camera camera);
1389e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    };
1390e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks
1391e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    /**
13923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * Registers a listener to be notified when the zoom value is updated by the
139336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li     * camera driver during smooth zoom.
13948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     *
13953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li     * @param listener the listener to notify
13968cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li     * @see #startSmoothZoom(int)
1397e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks     */
13983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li    public final void setZoomChangeListener(OnZoomChangeListener listener)
1399e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    {
14003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li        mZoomListener = listener;
1401e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks    }
14029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
14034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
14044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * Callback interface for face detected in the preview frame.
14054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
14064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
14074c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public interface FaceDetectionListener
14084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
14094c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
14104c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Notify the listener of the detected faces in the preview frame.
14114c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
141253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @param faces The detected faces in a list
1413464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @param camera  The {@link Camera} service object
14144c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1415f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li        void onFaceDetection(Face[] faces, Camera camera);
14164c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
14174c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
14184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1419c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Registers a listener to be notified about the faces detected in the
14204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * preview frame.
14214c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
14224c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @param listener the listener to notify
1423c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see #startFaceDetection()
14244c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
14254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void setFaceDetectionListener(FaceDetectionListener listener)
14264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    {
14274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceListener = listener;
14284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
14294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
14304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1431c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Starts the face detection. This should be called after preview is started.
14324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * The camera will notify {@link FaceDetectionListener} of the detected
14334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * faces in the preview frame. The detected faces may be the same as the
14344c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * previous ones. Applications should call {@link #stopFaceDetection} to
14354c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * stop the face detection. This method is supported if {@link
1436c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0.
14374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * If the face detection has started, apps should not call this again.
14384c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
14398c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)},
14404c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)}
14418c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * have no effect. The camera uses the detected faces to do auto-white balance,
14428c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * auto exposure, and autofocus.
14438c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
14448c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera
14458c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * will stop sending face callbacks. The last face callback indicates the
14468c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * areas used to do autofocus. After focus completes, face detection will
14478c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * resume sending face callbacks. If the apps call {@link
14488c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * #cancelAutoFocus()}, the face callbacks will also resume.</p>
14498c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     *
14508c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
14518c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming
14528c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * preview with {@link #startPreview()}, the apps should call this method
14538c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li     * again to resume face detection.</p>
14544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1455c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @throws IllegalArgumentException if the face detection is unsupported.
14564c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @throws RuntimeException if the method fails or the face detection is
14574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *         already running.
14584c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see FaceDetectionListener
14594c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     * @see #stopFaceDetection()
1460c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * @see Parameters#getMaxNumDetectedFaces()
14614c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1462c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li    public final void startFaceDetection() {
14634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        if (mFaceDetectionRunning) {
14644c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li            throw new RuntimeException("Face detection is already running");
14654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
1466c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        _startFaceDetection(CAMERA_FACE_DETECTION_HW);
14674c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = true;
14684c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
14694c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
14704c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1471c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li     * Stops the face detection.
14724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1473464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see #startFaceDetection()
14744c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
14754c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    public final void stopFaceDetection() {
14764c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        _stopFaceDetection();
14774c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        mFaceDetectionRunning = false;
14784c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
14794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
14804c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _startFaceDetection(int type);
14814c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    private native final void _stopFaceDetection();
14824c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
14834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    /**
1484464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * Information about a face identified through camera face detection.
148553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li     *
1486464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a
1487464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * list of face objects for use in focusing and metering.</p>
14884c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     *
1489464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez     * @see FaceDetectionListener
14904c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li     */
1491f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li    public static class Face {
1492c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        /**
1493c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * Create an empty face.
1494c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         */
1495bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Face() {
1496bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        }
1497bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li
14984c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
14994c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Bounds of the face. (-1000, -1000) represents the top-left of the
15004c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * camera field of view, and (1000, 1000) represents the bottom-right of
1501c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * the field of view. For example, suppose the size of the viewfinder UI
1502c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li         * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0).
15038c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * The corresponding viewfinder rect should be (0, 0, 400, 240). It is
15048c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * guaranteed left < right and top < bottom. The coordinates can be
15058c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * smaller than -1000 or bigger than 1000. But at least one vertex will
15068c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * be within (-1000, -1000) and (1000, 1000).
1507f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         *
1508f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * <p>The direction is relative to the sensor orientation, that is, what
1509f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li         * the sensor sees. The direction is not affected by the rotation or
15108c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. The face bounding
15118c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * rectangle does not provide any information about face orientation.</p>
15128c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         *
15138c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <p>Here is the matrix to convert driver coordinates to View coordinates
15148c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * in pixels.</p>
15158c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * <pre>
15168c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * Matrix matrix = new Matrix();
15178c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
15188c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Need mirror for front camera.
15198c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
15208c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.setScale(mirror ? -1 : 1, 1);
15218c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // This is the value for android.hardware.Camera.setDisplayOrientation.
15228c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postRotate(displayOrientation);
15238c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
15248c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * // UI coordinates range from (0, 0) to (width, height).
15258c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
15268c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
15278c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li         * </pre>
15284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1529464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
15304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1531bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public Rect rect;
15324c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
15334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
15348df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>The confidence level for the detection of the face. The range is 1 to
15358df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * 100. 100 is the highest confidence.</p>
15368df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         *
15378df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * <p>Depending on the device, even very low-confidence faces may be
15388df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * listed, so applications should filter out faces with low confidence,
15398df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * depending on the use case. For a typical point-and-shoot camera
15408df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * application that wishes to display rectangles around detected faces,
15418df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala         * filtering out faces with confidence less than 50 is recommended.</p>
15424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
1543464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
15444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
1545bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li        public int score;
1546d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1547d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1548d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * An unique id per face while the face is visible to the tracker. If
1549d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the face leaves the field-of-view and comes back, it will get a new
1550d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * id. This is an optional field, may not be supported on all devices.
1551d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * If not supported, id will always be set to -1. The optional fields
1552d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are supported as a set. Either they are all valid, or none of them
1553d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * are.
1554d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1555d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public int id = -1;
1556d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1557d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1558d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the left eye. The coordinates are in
1559d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1560d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1561d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1562d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1563d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1564d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point leftEye = null;
1565d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1566d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1567d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the right eye. The coordinates are
1568d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * in the same space as the ones for {@link #rect}.This is an optional
1569d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1570d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1571d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1572d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1573d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point rightEye = null;
1574d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua
1575d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        /**
1576d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * The coordinates of the center of the mouth.  The coordinates are in
1577d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * the same space as the ones for {@link #rect}. This is an optional
1578d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * field, may not be supported on all devices. If not supported, the
1579d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * value will always be set to null. The optional fields are supported
1580d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         * as a set. Either they are all valid, or none of them are.
1581d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua         */
1582d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua        public Point mouth = null;
15834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li    }
15844c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
1585bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    // Error codes match the enum in include/ui/Camera.h
1586bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1587bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1588bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Unspecified camera error.
1589bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1590bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
15919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_UNKNOWN = 1;
1592bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor
1593bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor    /**
1594bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Media server died. In this case, the application must release the
1595bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera object and instantiate a new one.
1596bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see Camera.ErrorCallback
1597bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     */
15989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int CAMERA_ERROR_SERVER_DIED = 100;
15999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
16009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1601bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Callback interface for camera error notification.
1602bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1603bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setErrorCallback(ErrorCallback)
16049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public interface ErrorCallback
16069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
16079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
16089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Callback for camera errors.
16099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param error   error code:
16109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <ul>
16119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_UNKNOWN}
16129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <li>{@link #CAMERA_ERROR_SERVER_DIED}
16139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * </ul>
16149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param camera  the Camera service object
16159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
16169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        void onError(int error, Camera camera);
16179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
16189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
16199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
16209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Registers a callback to be invoked when an error occurs.
1621bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @param cb The callback to run
16229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final void setErrorCallback(ErrorCallback cb)
16249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    {
16259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mErrorCallback = cb;
16269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
16279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
16289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final void native_setParameters(String params);
16299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private native final String native_getParameters();
16309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
16319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1632bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Changes the settings for this Camera service.
16339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
16349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param params the Parameters to use for this Camera service
163599a3f3e4e06b4370101ca97cc11dbe81d772fefaWu-cheng Li     * @throws RuntimeException if any parameter is invalid or not supported.
1636bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #getParameters()
16379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void setParameters(Parameters params) {
16397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        // If using preview allocations, don't allow preview size changes
16407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        if (mUsingPreviewAllocation) {
16417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size newPreviewSize = params.getPreviewSize();
16427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            Size currentPreviewSize = getParameters().getPreviewSize();
16437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            if (newPreviewSize.width != currentPreviewSize.width ||
16447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                    newPreviewSize.height != currentPreviewSize.height) {
16457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                throw new IllegalStateException("Cannot change preview size" +
16467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala                        " while a preview allocation is configured.");
16477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala            }
16487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala        }
16497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala
16509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        native_setParameters(params.flatten());
16519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
16529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
16539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1654bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Returns the current settings for this Camera service.
1655bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * If modifications are made to the returned Parameters, they must be passed
1656bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * to {@link #setParameters(Camera.Parameters)} to take effect.
1657bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     *
1658bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * @see #setParameters(Camera.Parameters)
16599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public Parameters getParameters() {
16619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        Parameters p = new Parameters();
16629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        String s = native_getParameters();
16639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        p.unflatten(s);
16649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return p;
16659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
16669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
16679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
16681c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * Returns an empty {@link Parameters} for testing purpose.
16691c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
1670f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa     * @return a Parameter object.
16711c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     *
16721c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     * @hide
16731c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li     */
16741c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    public static Parameters getEmptyParameters() {
16751c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        Camera camera = new Camera();
16761c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li        return camera.new Parameters();
16771c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    }
16781c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li
16791c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li    /**
1680bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Image size (width and height dimensions).
16819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
16829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Size {
16839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
16849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the dimensions for pictures.
16859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
16869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param w the photo width (pixels)
16879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param h the photo height (pixels)
16889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
16899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size(int w, int h) {
16909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            width = w;
16919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            height = h;
16929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
16934c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
16944c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Compares {@code obj} to this size.
16954c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
16964c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @param obj the object to compare this size with.
16974c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * @return {@code true} if the width and height of {@code obj} is the
16984c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         same as those of this size. {@code false} otherwise.
16994c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
17004c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
17014c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public boolean equals(Object obj) {
17024c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            if (!(obj instanceof Size)) {
17034c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li                return false;
17044c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            }
17054c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            Size s = (Size) obj;
17064c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width == s.width && height == s.height;
17074c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
17084c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        @Override
17094c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public int hashCode() {
17104c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return width * 32713 + height;
17114c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
17129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** width of the picture */
17139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int width;
17149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /** height of the picture */
17159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int height;
17169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
17179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
17189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
171932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The Area class is used for choosing specific metering and focus areas for
172032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the camera to use when calculating auto-exposure, auto-white balance, and
172132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * auto-focus.</p>
172232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
172332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>To find out how many simultaneous areas a given camera supports, use
172432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumMeteringAreas()} and
172532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area
172632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * selection is unsupported, these methods will return 0.</p>
172732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
172832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>Each Area consists of a rectangle specifying its bounds, and a weight
172932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * that determines its importance. The bounds are relative to the camera's
173032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * current field of view. The coordinates are mapped so that (-1000, -1000)
173132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * is always the top-left corner of the current field of view, and (1000,
173232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * 1000) is always the bottom-right corner of the current field of
173332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * view. Setting Areas with bounds outside that range is not allowed. Areas
173432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * with zero or negative width or height are not allowed.</p>
173532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     *
173632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * <p>The weight must range from 1 to 1000, and represents a weight for
173732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * every pixel in the area. This means that a large metering area with
173832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * the same weight as a smaller area will have more effect in the
173932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * metering result.  Metering areas can overlap and the driver
174032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala     * will add the weights in the overlap region.</p>
1741bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     *
1742bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setFocusAreas(List)
1743bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getFocusAreas()
1744bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumFocusAreas()
1745bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#setMeteringAreas(List)
1746bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMeteringAreas()
1747bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li     * @see Parameters#getMaxNumMeteringAreas()
174830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li     */
174930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    public static class Area {
175030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
175130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Create an area with specified rectangle and weight.
175230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
175332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param rect the bounds of the area.
175432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * @param weight the weight of the area.
175530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
175630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Area(Rect rect, int weight) {
175730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.rect = rect;
175830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            this.weight = weight;
175930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
176030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
176130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Compares {@code obj} to this area.
176230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
176330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @param obj the object to compare this area with.
176430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return {@code true} if the rectangle and weight of {@code obj} is
176530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *         the same as those of this area. {@code false} otherwise.
176630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
176730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        @Override
176830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public boolean equals(Object obj) {
176930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (!(obj instanceof Area)) {
177030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return false;
177130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
177230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            Area a = (Area) obj;
177330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (rect == null) {
177430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (a.rect != null) return false;
177530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } else {
177630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (!rect.equals(a.rect)) return false;
177730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
177830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return weight == a.weight;
177930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
178030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
1781bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
178232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Bounds of the area. (-1000, -1000) represents the top-left of the
178332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * camera field of view, and (1000, 1000) represents the bottom-right of
178432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the field of view. Setting bounds outside that range is not
178532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed. Bounds with zero or negative width or height are not
178632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * allowed.
1787bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
1788bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
1789bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
1790bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
179130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public Rect rect;
179230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
1793bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li        /**
179432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * Weight of the area. The weight must range from 1 to 1000, and
179532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * represents a weight for every pixel in the area. This means that a
179632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * large metering area with the same weight as a smaller area will have
179732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * more effect in the metering result.  Metering areas can overlap and
179832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * the driver will add the weights in the overlap region.
1799bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         *
1800bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getFocusAreas()
1801bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * @see Parameters#getMeteringAreas()
1802bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         */
180330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int weight;
1804bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li    }
180530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
180630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li    /**
1807bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * Camera service settings.
18089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
18099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>To make camera parameters take effect, applications have to call
1810bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera#setParameters(Camera.Parameters)}. For example, after
1811bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not
1812bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * actually changed until {@link Camera#setParameters(Camera.Parameters)}
1813bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * is called with the changed parameters object.
18149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     *
18159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * <p>Different devices may have different camera capabilities, such as
18169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * picture size or flash modes. The application should query the camera
18179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li     * capabilities before setting parameters. For example, the application
1818bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * should call {@link Camera.Parameters#getSupportedColorEffects()} before
1819bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * calling {@link Camera.Parameters#setColorEffect(String)}. If the
1820bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * camera does not support color effects,
1821bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor     * {@link Camera.Parameters#getSupportedColorEffects()} will return null.
18229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
18239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public class Parameters {
18249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter keys to communicate with the camera driver.
18259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_SIZE = "preview-size";
18269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FORMAT = "preview-format";
18279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
1828454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
18299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_SIZE = "picture-size";
18309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_PICTURE_FORMAT = "picture-format";
18314c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
18329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width";
18339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height";
18349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality";
18359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_JPEG_QUALITY = "jpeg-quality";
18369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ROTATION = "rotation";
18379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LATITUDE = "gps-latitude";
18389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_LONGITUDE = "gps-longitude";
18399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_ALTITUDE = "gps-altitude";
18409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_GPS_TIMESTAMP = "gps-timestamp";
1841055c986ab841f8f758398841730f1e90313b132aRay Chen        private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method";
18429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_WHITE_BALANCE = "whitebalance";
18439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_EFFECT = "effect";
18449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_ANTIBANDING = "antibanding";
18459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_SCENE_MODE = "scene-mode";
18469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String KEY_FLASH_MODE = "flash-mode";
184736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        private static final String KEY_FOCUS_MODE = "focus-mode";
184830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_FOCUS_AREAS = "focus-areas";
184930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas";
18506c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_FOCAL_LENGTH = "focal-length";
18516c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle";
18526c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle";
1853ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation";
185424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation";
185524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation";
185624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step";
18573773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock";
18583773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported";
1859d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock";
1860d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported";
1861e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_METERING_AREAS = "metering-areas";
1862e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas";
18638cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM = "zoom";
18648cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_MAX_ZOOM = "max-zoom";
18658cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_RATIOS = "zoom-ratios";
18668cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_ZOOM_SUPPORTED = "zoom-supported";
18678cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported";
1868e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        private static final String KEY_FOCUS_DISTANCES = "focus-distances";
1869dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_VIDEO_SIZE = "video-size";
1870dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO =
1871dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong                                            "preferred-preview-size-for-video";
18724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw";
18734c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw";
187425d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        private static final String KEY_RECORDING_HINT = "recording-hint";
187598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported";
1876037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION = "video-stabilization";
1877037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported";
1878e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
18799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parameter key suffix for supported values.
18809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String SUPPORTED_VALUES_SUFFIX = "-values";
18819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18828cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        private static final String TRUE = "true";
18833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        private static final String FALSE = "false";
18848cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li
18859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for white balance settings.
18869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_AUTO = "auto";
18879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_INCANDESCENT = "incandescent";
18889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent";
18899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent";
18909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_DAYLIGHT = "daylight";
18919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight";
18929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_TWILIGHT = "twilight";
18939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String WHITE_BALANCE_SHADE = "shade";
18949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
18959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for color effect settings.
18969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NONE = "none";
18979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_MONO = "mono";
18989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_NEGATIVE = "negative";
18999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SOLARIZE = "solarize";
19009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_SEPIA = "sepia";
19019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_POSTERIZE = "posterize";
19029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_WHITEBOARD = "whiteboard";
19039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_BLACKBOARD = "blackboard";
19049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String EFFECT_AQUA = "aqua";
19059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
19069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for antibanding settings.
19079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_AUTO = "auto";
19089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_50HZ = "50hz";
19099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_60HZ = "60hz";
19109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String ANTIBANDING_OFF = "off";
19119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
19129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Values for flash mode settings.
19139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
19149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will not be fired.
19159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
19169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_OFF = "off";
191736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
19189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
1919068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will be fired automatically when required. The flash may be fired
1920068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * during preview, auto-focus, or snapshot depending on the driver.
19219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
19229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_AUTO = "auto";
192336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
19249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
1925068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Flash will always be fired during snapshot. The flash may also be
1926068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * fired during preview or auto-focus depending on the driver.
19279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
19289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_ON = "on";
192936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
19309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
19319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Flash will be fired in red-eye reduction mode.
19329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
19339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String FLASH_MODE_RED_EYE = "red-eye";
193436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
193536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
1936068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * Constant emission of light during preview, auto-focus and snapshot.
1937068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li         * This can also be used for video recording.
193836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
1939068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li        public static final String FLASH_MODE_TORCH = "torch";
19409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
194100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
194200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Scene mode is off.
194300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_AUTO = "auto";
194500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
194600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
194700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
194800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_SPORTS}.
194900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_ACTION = "action";
195100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
195200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
195300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures.
195400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PORTRAIT = "portrait";
195600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
195700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
195800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on distant objects.
195900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_LANDSCAPE = "landscape";
196100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
196200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
196300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos at night.
196400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT = "night";
196600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
196700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
196800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take people pictures at night.
196900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait";
197100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
197200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
197300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos in a theater. Flash light is off.
197400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_THEATRE = "theatre";
197600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
197700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
197800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the beach.
197900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_BEACH = "beach";
198100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
198200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
198300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take pictures on the snow.
198400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SNOW = "snow";
198600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
198700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
198800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take sunset photos.
198900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SUNSET = "sunset";
199100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
199200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
199300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Avoid blurry pictures (for example, due to hand shake).
199400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
19959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto";
199600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
199700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
199800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * For shooting firework displays.
199900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
20009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_FIREWORKS = "fireworks";
200100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
200200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
200300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take photos of fast moving objects. Same as {@link
200400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * #SCENE_MODE_ACTION}.
200500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
20069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_SPORTS = "sports";
200700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
200800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
200900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Take indoor low-light shot.
201000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
20119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_PARTY = "party";
201200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li
201300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li        /**
201400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         * Capture the naturally warm color of scenes lit by candles.
201500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li         */
20169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public static final String SCENE_MODE_CANDLELIGHT = "candlelight";
20179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
2018c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2019c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Applications are looking for a barcode. Camera driver will be
2020c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * optimized for barcode reading.
2021c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2022c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String SCENE_MODE_BARCODE = "barcode";
2023c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
202436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
2025da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * Capture a scene using high dynamic range imaging techniques. The
2026da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * camera will return an image that has an extended dynamic range
2027da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * compared to a regular capture. Capturing such an image may take
2028da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * longer than a regular capture.
2029da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         */
2030da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        public static final String SCENE_MODE_HDR = "hdr";
2031da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala
2032da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala        /**
2033f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Auto-focus mode. Applications should call {@link
2034f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * #autoFocus(AutoFocusCallback)} to start the focus in this mode.
203536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
203636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_AUTO = "auto";
203736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
203836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
203936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is set at infinity. Applications should not call
204036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} in this mode.
204136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
204236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_INFINITY = "infinity";
2043f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li
2044f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li        /**
2045f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * Macro (close-up) focus mode. Applications should call
2046f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * {@link #autoFocus(AutoFocusCallback)} to start the focus in this
2047f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * mode.
2048f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         */
204936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_MACRO = "macro";
205036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
205136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
205236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Focus is fixed. The camera is always in this mode if the focus is not
205336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * adjustable. If the camera has auto-focus, this mode can fix the
205436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * focus, which is usually at hyperfocal distance. Applications should
205536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * not call {@link #autoFocus(AutoFocusCallback)} in this mode.
205636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
205736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public static final String FOCUS_MODE_FIXED = "fixed";
205836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
2059c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        /**
2060c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Extended depth of field (EDOF). Focusing is done digitally and
2061c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * continuously. Applications should not call {@link
2062c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode.
2063c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         */
2064c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li        public static final String FOCUS_MODE_EDOF = "edof";
2065c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li
2066699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li        /**
2067d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * Continuous auto focus mode intended for video recording. The camera
2068b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. This is the best choice for video
2069b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * recording because the focus changes smoothly . Applications still can
2070b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * call {@link #takePicture(Camera.ShutterCallback,
2071b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the
2072b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * subject may not be in focus. Auto focus starts when the parameter is
207353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * set.
207453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
207553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * <p>Since API level 14, applications can call {@link
207653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will
207753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * immediately return with a boolean that indicates whether the focus is
207853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * sharp or not. The focus position is locked after autoFocus call. If
207953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * applications want to resume the continuous focus, cancelAutoFocus
208053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * must be called. Restarting the preview will not resume the continuous
208153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * autofocus. To stop continuous focus, applications should change the
208253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * focus mode to other modes.
208353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
208453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_PICTURE
2085d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         */
2086d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video";
2087699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li
2088b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        /**
2089b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * Continuous auto focus mode intended for taking pictures. The camera
2090b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * continuously tries to focus. The speed of focus change is more
2091b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
209253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * starts when the parameter is set.
209353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         *
20940f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
20950f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * this mode. If the autofocus is in the middle of scanning, the focus
20960f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * callback will return when it completes. If the autofocus is not
20970f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * scanning, the focus callback will immediately return with a boolean
20980f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * that indicates whether the focus is sharp or not. The apps can then
20990f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * decide if they want to take a picture immediately or to change the
21000f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * focus mode to auto, and run a full autofocus cycle. The focus
21010f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * position is locked after autoFocus call. If applications want to
21020f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * resume the continuous focus, cancelAutoFocus must be called.
21030f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * Restarting the preview will not resume the continuous autofocus. To
21040f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * stop continuous focus, applications should change the focus mode to
21050f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li         * other modes.
2106b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         *
2107b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
2108b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li         */
2109b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li        public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture";
2110b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li
2111e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Indices for focus distance array.
2112e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2113e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of near focus distance for use with
2114e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2115e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2116e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_NEAR_INDEX = 0;
2117e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2118e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2119e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of optimal focus distance for use with
2120e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2121e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2122e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1;
2123e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2124e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
2125e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * The array index of far focus distance for use with
2126e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * {@link #getFocusDistances(float[])}.
2127e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
2128e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public static final int FOCUS_DISTANCE_FAR_INDEX = 2;
2129e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
2130ca099614841bc619f217dfa088da630a7eb1ab65Wu-cheng Li        /**
2131454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of minimum preview fps for use with {@link
2132454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2133454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2134454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2135454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MIN_INDEX = 0;
2136454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2137454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2138454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * The array index of maximum preview fps for use with {@link
2139454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getPreviewFpsRange(int[])} or {@link
2140454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange()}.
2141454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2142454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public static final int PREVIEW_FPS_MAX_INDEX = 1;
2143454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
21449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Formats for setPreviewFormat and setPictureFormat.
21459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
21469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
2147eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang        private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv";
214810a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li        private static final String PIXEL_FORMAT_YUV420P = "yuv420p";
21499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_RGB565 = "rgb565";
21509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private static final String PIXEL_FORMAT_JPEG = "jpeg";
215170fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li        private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb";
21529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
21539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private HashMap<String, String> mMap;
21549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private Parameters() {
21560a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            mMap = new HashMap<String, String>(64);
21579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
21609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Writes the current Parameters to the log.
21619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @hide
21629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @deprecated
21639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
21649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void dump() {
21659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            Log.e(TAG, "dump: size=" + mMap.size());
21669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
21679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                Log.e(TAG, "dump: " + k + "=" + mMap.get(k));
21689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
21699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
21729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Creates a single string with all the parameters set in
21739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
21749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #unflatten(String)} method does the reverse.</p>
21759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return a String with all values from this Parameters object, in
21779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *         semi-colon delimited key-value pairs
21789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
21799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String flatten() {
21800a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            StringBuilder flattened = new StringBuilder(128);
21819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            for (String k : mMap.keySet()) {
21829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(k);
21839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append("=");
21849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(mMap.get(k));
21859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                flattened.append(";");
21869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
21879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            // chop off the extra semicolon at the end
21889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            flattened.deleteCharAt(flattened.length()-1);
21899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return flattened.toString();
21909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
21919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
21929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
21939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Takes a flattened string of parameters and adds each one to
21949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * this Parameters object.
21959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * <p>The {@link #flatten()} method does the reverse.</p>
21969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
21979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param flattened a String of parameters (key-value paired) that
21989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *                  are semi-colon delimited
21999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void unflatten(String flattened) {
22019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.clear();
22029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
22030a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';');
22040a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(flattened);
22050a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String kv : splitter) {
22069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                int pos = kv.indexOf('=');
22079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                if (pos == -1) {
22089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                    continue;
22099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                }
22109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String k = kv.substring(0, pos);
22119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                String v = kv.substring(pos + 1);
22129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                mMap.put(k, v);
22139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
22149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
22169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void remove(String key) {
22179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.remove(key);
22189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets a String parameter.
22229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
22249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the String value of the parameter
22259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, String value) {
2227cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) {
2228cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)");
22299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
22309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
2231cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala            if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) {
2232cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala                Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)");
22339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                return;
22349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
22359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.put(key, value);
22379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets an integer parameter.
22419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key   the key name for the parameter
22439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param value the int value of the parameter
22449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void set(String key, int value) {
22469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            mMap.put(key, Integer.toString(value));
22479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2249e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        private void set(String key, List<Area> areas) {
2250f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (areas == null) {
2251f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, "(0,0,0,0,0)");
2252f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            } else {
2253f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                StringBuilder buffer = new StringBuilder();
2254f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                for (int i = 0; i < areas.size(); i++) {
2255f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Area area = areas.get(i);
2256f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    Rect rect = area.rect;
2257f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append('(');
2258f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.left);
2259f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2260f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.top);
2261f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2262f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.right);
2263f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2264f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(rect.bottom);
2265f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(',');
2266f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(area.weight);
2267f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    buffer.append(')');
2268f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    if (i != areas.size() - 1) buffer.append(',');
2269f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
2270f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                set(key, buffer.toString());
2271e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            }
2272e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
2273e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
22749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of a String parameter.
22769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
22789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the String value of the parameter
22799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public String get(String key) {
22819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mMap.get(key);
22829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
22859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the value of an integer parameter.
22869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
22879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param key the key name for the parameter
22889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the int value of the parameter
22899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
22909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getInt(String key) {
22919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return Integer.parseInt(mMap.get(key));
22929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
22939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
22949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
229526274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * Sets the dimensions for preview pictures. If the preview has already
229626274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * started, applications should stop the preview first before changing
229726274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li         * preview size.
22989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2299c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * The sides of width and height are based on camera orientation. That
2300c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * is, the preview size is the size before it is rotated by display
2301c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation. So applications need to consider the display orientation
2302c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * while setting preview size. For example, suppose the camera supports
2303c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * both 480x320 and 320x480 preview sizes. The application wants a 3:2
2304c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * preview ratio. If the display orientation is set to 0 or 180, preview
2305c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * size should be set to 480x320. If the display orientation is set to
2306c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * 90 or 270, preview size should be set to 320x480. The display
2307c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * orientation should also be considered while setting picture size and
2308c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * thumbnail size.
2309c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
23109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the pictures, in pixels
23119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the pictures, in pixels
2312c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setDisplayOrientation(int)
2313c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
2314c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPictureSize(int, int)
2315c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setJpegThumbnailSize(int, int)
23169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
23179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewSize(int width, int height) {
23189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
23199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_SIZE, v);
23209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
23239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimensions setting for preview pictures.
23249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
2325dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a Size object with the width and height setting
23269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for the preview picture
23279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
23289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPreviewSize() {
23299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PREVIEW_SIZE);
23309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
23319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
23329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
23349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview sizes.
23359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
23363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
23379c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li         *         with at least one element.
23389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPreviewSizes() {
23409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX);
23419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
23429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
23439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
23449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
234532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the supported video frame sizes that can be used by
234632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * MediaRecorder.</p>
2347dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
234832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>If the returned list is not null, the returned list will contain at
2349dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * least one Size and one of the sizes in the returned list must be
2350dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * passed to MediaRecorder.setVideoSize() for camcorder application if
2351dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * camera is used as the video source. In this case, the size of the
2352dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview can be different from the resolution of the recorded video
235332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * during video recording.</p>
2354dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2355dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return a list of Size object if camera has separate preview and
2356dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video output; otherwise, null is returned.
2357dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getPreferredPreviewSizeForVideo()
2358dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2359dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public List<Size> getSupportedVideoSizes() {
2360dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX);
2361dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return splitSize(str);
2362dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2363dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2364dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
2365dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * Returns the preferred or recommended preview size (width and height)
2366dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * in pixels for video recording. Camcorder applications should
2367dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * set the preview size to a value that is not larger than the
2368dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preferred preview size. In other words, the product of the width
2369dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * and height of the preview size should not be larger than that of
2370dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * the preferred preview size. In addition, we recommend to choose a
2371dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * preview size that has the same aspect ratio as the resolution of
2372dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * video to be recorded.
2373dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *
2374dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @return the preferred preview size (width and height) in pixels for
2375dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         video recording if getSupportedVideoSizes() does not return
2376dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         *         null; otherwise, null is returned.
2377dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         * @see #getSupportedVideoSizes()
2378dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong         */
2379dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        public Size getPreferredPreviewSizeForVideo() {
2380dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
2381dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong            return strToSize(pair);
2382dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        }
2383dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong
2384dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong        /**
238532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If
23864c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * applications set both width and height to 0, EXIF will not contain
238732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * thumbnail.</p>
23889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
238932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
239032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2391c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
23929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width of the thumbnail, in pixels
23939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height of the thumbnail, in pixels
2394c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
23959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
23969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailSize(int width, int height) {
23979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_WIDTH, width);
23989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_HEIGHT, height);
23999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the dimensions for EXIF thumbnail in Jpeg picture.
24039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
24049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting for the EXIF
24059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         thumbnails
24069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public Size getJpegThumbnailSize() {
24089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH),
24099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                            getInt(KEY_JPEG_THUMBNAIL_HEIGHT));
24109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
24134c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         * Gets the supported jpeg thumbnail sizes.
24144c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *
24153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of Size object. This method will always return a list
24164c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         with at least two elements. Size 0,0 (no thumbnail) is always
24174c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         *         supported.
24184c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li         */
24194c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        public List<Size> getSupportedJpegThumbnailSizes() {
24204c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX);
24214c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li            return splitSize(str);
24224c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        }
24234c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li
24244c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li        /**
24259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the quality of the EXIF thumbnail in Jpeg picture.
24269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
24279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of the EXIF thumbnail. The range is 1
24289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
24299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegThumbnailQuality(int quality) {
24319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_THUMBNAIL_QUALITY, quality);
24329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
24359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the EXIF thumbnail in Jpeg picture.
24369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
24379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG quality setting of the EXIF thumbnail.
24389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegThumbnailQuality() {
24409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_THUMBNAIL_QUALITY);
24419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
24449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets Jpeg quality of captured picture.
24459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *
24469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param quality the JPEG quality of captured picture. The range is 1
24479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                to 100, with 100 being the best.
24489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setJpegQuality(int quality) {
24509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_JPEG_QUALITY, quality);
24519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Returns the quality setting for the JPEG picture.
24559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return the JPEG picture quality setting.
24579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public int getJpegQuality() {
24599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_JPEG_QUALITY);
24609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2463a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Sets the rate at which preview frames are received. This is the
2464a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * target frame rate. The actual frame rate depends on the driver.
24659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param fps the frame rate (frames per second)
24675f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #setPreviewFpsRange(int,int)}
24689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24695f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
24709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFrameRate(int fps) {
24719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FRAME_RATE, fps);
24729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
24749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
2475a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * Returns the setting for the rate at which preview frames are
2476a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * received. This is the target frame rate. The actual frame rate
2477a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li         * depends on the driver.
24789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @return the frame rate setting (frames per second)
24805f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getPreviewFpsRange(int[])}
24819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
24825f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
24839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFrameRate() {
24849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return getInt(KEY_PREVIEW_FRAME_RATE);
24859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
24869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
24879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
24889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported preview frame rates.
24899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
24903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview frame rates. null if preview
24913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         frame rate setting is not supported.
24925f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li         * @deprecated replaced by {@link #getSupportedPreviewFpsRange()}
24939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
24945f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li        @Deprecated
24959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFrameRates() {
24969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX);
24979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitInt(str);
24989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
24999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
25009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
25014a68e3c26dd2512c319071dc20074baa6e7d171fHai Guo         * Sets the minimum and maximum preview fps. This controls the rate of
25021620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li         * preview frames received in {@link PreviewCallback}. The minimum and
2503454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum preview fps must be one of the elements from {@link
2504454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * #getSupportedPreviewFpsRange}.
2505454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2506454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param min the minimum preview fps (scaled by 1000).
2507454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @param max the maximum preview fps (scaled by 1000).
2508454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @throws RuntimeException if fps range is invalid.
2509454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
2510454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2511454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2512454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void setPreviewFpsRange(int min, int max) {
2513454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
2514454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2515454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2516454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2517454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Returns the current minimum and maximum preview fps. The values are
2518454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
2519454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2520454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return range the minimum and maximum preview fps (scaled by 1000).
2521454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2522454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2523454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #getSupportedPreviewFpsRange()
2524454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2525454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public void getPreviewFpsRange(int[] range) {
2526454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (range == null || range.length != 2) {
2527454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                throw new IllegalArgumentException(
25285f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li                        "range must be an array with two elements.");
2529454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
2530454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
2531454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2532454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2533454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
2534454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * Gets the supported preview fps (frame-per-second) ranges. Each range
2535454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * contains a minimum fps and maximum fps. If minimum fps equals to
2536454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * maximum fps, the camera outputs frames in fixed frame rate. If not,
2537454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * the camera outputs frames in auto frame rate. The actual frame rate
2538454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * fluctuates between the minimum and the maximum. The values are
2539454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * multiplied by 1000 and represented in integers. For example, if frame
2540454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * rate is 26.623 frames per second, the value is 26623.
2541454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *
2542454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @return a list of supported preview fps ranges. This method returns a
2543454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         list with at least one element. Every element is an int array
2544454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         of two values - minimum fps and maximum fps. The list is
2545454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         sorted from small to large (first by maximum fps and then
2546454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         *         minimum fps).
2547454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MIN_INDEX
2548454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         * @see #PREVIEW_FPS_MAX_INDEX
2549454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li         */
2550454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        public List<int[]> getSupportedPreviewFpsRange() {
2551454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
2552454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return splitRange(str);
2553454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
2554454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
2555454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        /**
25567478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         * Sets the image format for preview pictures.
2557da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main         * <p>If this is never called, the default format will be
2558a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * {@link android.graphics.ImageFormat#NV21}, which
2559df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main         * uses the NV21 encoding format.</p>
25607478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
2561951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of
2562951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the available preview formats.
2563951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2564951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>It is strongly recommended that either
2565951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#NV21} or
2566951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12} is used, since
2567951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * they are supported by all camera devices.</p>
2568951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2569951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <p>For YV12, the image buffer that is received is not necessarily
2570951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * tightly packed, as there may be padding at the end of each row of
2571951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * pixel data, as described in
2572951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@link android.graphics.ImageFormat#YV12}. For camera callback data,
2573951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * it can be assumed that the stride of the Y and UV data is the
2574951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * smallest possible that meets the alignment requirements. That is, if
2575951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * the preview size is <var>width x height</var>, then the following
2576951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * equations describe the buffer index for the beginning of row
2577951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <var>y</var> for the Y plane and row <var>c</var> for the U and V
2578951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * planes:
2579951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2580951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * {@code
2581951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * <pre>
2582951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yStride   = (int) ceil(width / 16.0) * 16;
2583951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvStride  = (int) ceil( (yStride / 2) / 16.0) * 16;
2584951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * ySize     = yStride * height;
2585951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uvSize    = uvStride * height / 2;
2586951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * yRowIndex = yStride * y;
2587951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * uRowIndex = ySize + uvSize + uvStride * c;
2588951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * vRowIndex = ySize + uvStride * c;
2589951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * size      = ySize + uvSize * 2;</pre>
2590951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * }
2591951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2592951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @param pixel_format the desired preview picture format, defined by
2593951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   one of the {@link android.graphics.ImageFormat} constants.  (E.g.,
2594951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.NV21</var> (default), or
2595951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *   <var>ImageFormat.YV12</var>)
2596951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         *
2597a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
2598951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats
25999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPreviewFormat(int pixel_format) {
26019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
26029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
26039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
26049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
26059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
26069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PREVIEW_FORMAT, s);
26089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * Returns the image format for preview frames got from
26129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * {@link PreviewCallback}.
26137478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li         *
26143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the preview format.
26153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
2616951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
26179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPreviewFormat() {
26199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT));
26209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
26229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2623f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21}
2624f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported. {@link android.graphics.ImageFormat#YV12}
2625f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li         * is always supported since API level 12.
26269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported preview formats. This method will always
26283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
26293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
2630951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala         * @see #setPreviewFormat
26319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPreviewFormats() {
26339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX);
2634eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            ArrayList<Integer> formats = new ArrayList<Integer>();
2635eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            for (String s : split(str)) {
2636eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                int f = pixelFormatForCameraFormat(s);
2637a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
2638eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang                formats.add(f);
2639eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            }
2640eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            return formats;
26419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
264432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Sets the dimensions for pictures.</p>
26459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
264632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Applications need to consider the display orientation. See {@link
264732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * #setPreviewSize(int,int)} for reference.</p>
2648c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
26499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param width  the width for pictures, in pixels
26509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * @param height the height for pictures, in pixels
2651c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         * @see #setPreviewSize(int,int)
2652c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li         *
26539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureSize(int width, int height) {
26559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String v = Integer.toString(width) + "x" + Integer.toString(height);
26569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_SIZE, v);
26579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the dimension setting for pictures.
26619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return a Size object with the height and width setting
26639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         *          for pictures
26649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public Size getPictureSize() {
26669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String pair = get(KEY_PICTURE_SIZE);
26679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return strToSize(pair);
26689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
26699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
26719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture sizes.
26729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported picture sizes. This method will always
26743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
26759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
26769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Size> getSupportedPictureSizes() {
26779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX);
26789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return splitSize(str);
26799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
26829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Sets the image format for pictures.
26839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
26849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param pixel_format the desired picture format
2685a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                     (<var>ImageFormat.NV21</var>,
2686a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.RGB_565</var>, or
2687a696f5d667227365da732481770767dcb330dd23Mathias Agopian         *                      <var>ImageFormat.JPEG</var>)
2688a696f5d667227365da732481770767dcb330dd23Mathias Agopian         * @see android.graphics.ImageFormat
26899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
26909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public void setPictureFormat(int pixel_format) {
26919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            String s = cameraFormatForPixelFormat(pixel_format);
26929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (s == null) {
26939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
26949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid pixel_format=" + pixel_format);
26959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
26969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
26979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_PICTURE_FORMAT, s);
26989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
26999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        /**
27019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         * Returns the image format for pictures.
27029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return the picture format
27043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
27059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project         */
27069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        public int getPictureFormat() {
27079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT));
27089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
27099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
27109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
27119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported picture formats.
27129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
27133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return supported picture formats. This method will always return a
27143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         list with at least one element.
27153f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see android.graphics.ImageFormat
27169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
27179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<Integer> getSupportedPictureFormats() {
27189c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX);
27199c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            ArrayList<Integer> formats = new ArrayList<Integer>();
27209c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            for (String s : split(str)) {
27219c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                int f = pixelFormatForCameraFormat(s);
2722a696f5d667227365da732481770767dcb330dd23Mathias Agopian                if (f == ImageFormat.UNKNOWN) continue;
27239c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li                formats.add(f);
27249c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            }
27259c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li            return formats;
27269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private String cameraFormatForPixelFormat(int pixel_format) {
27299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            switch(pixel_format) {
2730a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV16:      return PIXEL_FORMAT_YUV422SP;
2731a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.NV21:      return PIXEL_FORMAT_YUV420SP;
2732a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.YUY2:      return PIXEL_FORMAT_YUV422I;
273310a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            case ImageFormat.YV12:      return PIXEL_FORMAT_YUV420P;
2734a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.RGB_565:   return PIXEL_FORMAT_RGB565;
2735a696f5d667227365da732481770767dcb330dd23Mathias Agopian            case ImageFormat.JPEG:      return PIXEL_FORMAT_JPEG;
273670fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li            case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB;
2737a696f5d667227365da732481770767dcb330dd23Mathias Agopian            default:                    return null;
27389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            }
27399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        private int pixelFormatForCameraFormat(String format) {
27429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            if (format == null)
2743a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.UNKNOWN;
27449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV422SP))
2746a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV16;
27479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420SP))
2749a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.NV21;
27509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2751eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang            if (format.equals(PIXEL_FORMAT_YUV422I))
2752a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.YUY2;
2753eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang
275410a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li            if (format.equals(PIXEL_FORMAT_YUV420P))
275510a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li                return ImageFormat.YV12;
275610a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li
27579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_RGB565))
2758a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.RGB_565;
27599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (format.equals(PIXEL_FORMAT_JPEG))
2761a696f5d667227365da732481770767dcb330dd23Mathias Agopian                return ImageFormat.JPEG;
27629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2763a696f5d667227365da732481770767dcb330dd23Mathias Agopian            return ImageFormat.UNKNOWN;
27649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
27659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
27678969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * Sets the clockwise rotation angle in degrees relative to the
27688969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * orientation of the camera. This affects the pictures returned from
27698969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * JPEG {@link PictureCallback}. The camera driver may set orientation
27708969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * in the EXIF header without rotating the picture. Or the driver may
27718969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li         * rotate the picture and the EXIF thumbnail. If the Jpeg picture is
2772a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotated, the orientation in the EXIF header will be missing or 1 (row
2773a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * #0 is top and column #0 is left side).
2774a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
2775a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
2776a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * If applications want to rotate the picture to match the orientation
2777a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * of what users see, apps should use
2778a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.view.OrientationEventListener} and
2779a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * {@link android.hardware.Camera.CameraInfo}. The value from
2780a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * OrientationEventListener is relative to the natural orientation of
2781a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the device. CameraInfo.orientation is the angle between camera
2782a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * orientation and natural device orientation. The sum of the two is the
2783a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * rotation angle for back-facing camera. The difference of the two is
2784a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * the rotation angle for front-facing camera. Note that the JPEG
2785a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * pictures of front-facing cameras are not mirrored as in preview
2786a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * display.
2787a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         *
2788a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * <p>
2789a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin         * For example, suppose the natural orientation of the device is
27902fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * portrait. The device is rotated 270 degrees clockwise, so the device
27912fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 270. Suppose a back-facing camera sensor is mounted in
27922fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * landscape and the top side of the camera sensor is aligned with the
27932fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * right edge of the display in natural orientation. So the camera
27942fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         * orientation is 90. The rotation should be set to 0 (270 + 90).
27952fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
279669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick         * <p>The reference code is as follows.
27972fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
2798e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * <pre>
27999a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main         * public void onOrientationChanged(int orientation) {
28002fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     if (orientation == ORIENTATION_UNKNOWN) return;
28012fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.CameraInfo info =
28022fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *            new android.hardware.Camera.CameraInfo();
28032fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     android.hardware.Camera.getCameraInfo(cameraId, info);
28042fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *     orientation = (orientation + 45) / 90 * 90;
28052fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     int rotation = 0;
28062fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
28072fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation - orientation + 360) % 360;
28082fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     } else {  // back-facing camera
28092fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *         rotation = (info.orientation + orientation) % 360;
28102fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     }
28112fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li         *     mParameters.setRotation(rotation);
28122fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * }
2813e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala         * </pre>
28142fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *
28152fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @param rotation The rotation angle in degrees relative to the
28162fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 orientation of the camera. Rotation can only be 0,
28172fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         *                 90, 180 or 270.
28189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @throws IllegalArgumentException if rotation value is invalid.
28199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @see android.view.OrientationEventListener
28202fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li         * @see #getCameraInfo(int, CameraInfo)
28219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setRotation(int rotation) {
28239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (rotation == 0 || rotation == 90 || rotation == 180
28249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                    || rotation == 270) {
28259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                set(KEY_ROTATION, Integer.toString(rotation));
28269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            } else {
28279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                throw new IllegalArgumentException(
28289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                        "Invalid rotation=" + rotation);
28299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
28309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS latitude coordinate. This will be stored in JPEG EXIF
28349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
28359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param latitude GPS latitude coordinate.
28379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLatitude(double latitude) {
28399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LATITUDE, Double.toString(latitude));
28409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS longitude coordinate. This will be stored in JPEG EXIF
28449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * header.
28459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param longitude GPS longitude coordinate.
28479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsLongitude(double longitude) {
28499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_LONGITUDE, Double.toString(longitude));
28509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS altitude. This will be stored in JPEG EXIF header.
28549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param altitude GPS altitude in meters.
28569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsAltitude(double altitude) {
28589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_ALTITUDE, Double.toString(altitude));
28599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets GPS timestamp. This will be stored in JPEG EXIF header.
28639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @param timestamp GPS timestamp (UTC in seconds since January 1,
28659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *                  1970).
28669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setGpsTimestamp(long timestamp) {
28689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_GPS_TIMESTAMP, Long.toString(timestamp));
28699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
2872e208377fbab6b90f41e68699700942a81f4caaebRay Chen         * Sets GPS processing method. It will store up to 32 characters
2873055c986ab841f8f758398841730f1e90313b132aRay Chen         * in JPEG EXIF header.
2874055c986ab841f8f758398841730f1e90313b132aRay Chen         *
2875055c986ab841f8f758398841730f1e90313b132aRay Chen         * @param processing_method The processing method to get this location.
2876055c986ab841f8f758398841730f1e90313b132aRay Chen         */
2877055c986ab841f8f758398841730f1e90313b132aRay Chen        public void setGpsProcessingMethod(String processing_method) {
2878055c986ab841f8f758398841730f1e90313b132aRay Chen            set(KEY_GPS_PROCESSING_METHOD, processing_method);
2879055c986ab841f8f758398841730f1e90313b132aRay Chen        }
2880055c986ab841f8f758398841730f1e90313b132aRay Chen
2881055c986ab841f8f758398841730f1e90313b132aRay Chen        /**
28829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Removes GPS latitude, longitude, altitude, and timestamp from the
28839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * parameters.
28849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
28859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void removeGpsData() {
28869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LATITUDE);
28879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_LONGITUDE);
28889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_ALTITUDE);
28899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            remove(KEY_GPS_TIMESTAMP);
2890055c986ab841f8f758398841730f1e90313b132aRay Chen            remove(KEY_GPS_PROCESSING_METHOD);
28919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
28929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
28939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
28949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current white balance setting.
28959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
28963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current white balance. null if white balance setting is not
28973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
28983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_AUTO
28993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_INCANDESCENT
29003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_FLUORESCENT
29013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_WARM_FLUORESCENT
29023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_DAYLIGHT
29033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT
29043f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_TWILIGHT
29053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #WHITE_BALANCE_SHADE
29063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *
29079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getWhiteBalance() {
29099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_WHITE_BALANCE);
29109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
291316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * Sets the white balance. Changing the setting will release the
2914b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * auto-white balance lock. It is recommended not to change white
2915b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li         * balance and AWB lock at the same time.
29169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new white balance.
29183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
2919037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
29209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setWhiteBalance(String value) {
2922b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            String oldValue = get(KEY_WHITE_BALANCE);
2923b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (same(value, oldValue)) return;
29249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_WHITE_BALANCE, value);
292516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE);
29269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported white balance.
29309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported white balance. null if white balance
29323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
29333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getWhiteBalance()
29349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedWhiteBalance() {
29369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX);
29379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
29389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current color effect setting.
29429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29433f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current color effect. null if color effect
29449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
29453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NONE
29463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_MONO
29473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_NEGATIVE
29483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SOLARIZE
29493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_SEPIA
29503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_POSTERIZE
29513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_WHITEBOARD
29523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_BLACKBOARD
29533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #EFFECT_AQUA
29549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getColorEffect() {
29569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_EFFECT);
29579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the current color effect setting.
29619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value new color effect.
29633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
29649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setColorEffect(String value) {
29669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_EFFECT, value);
29679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported color effects.
29719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29723f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported color effects. null if color effect
29739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
29743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getColorEffect()
29759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedColorEffects() {
29779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX);
29789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
29799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current antibanding setting.
29849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29853f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current antibanding. null if antibanding setting is not
29863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
29873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_AUTO
29883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_50HZ
29893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_60HZ
29903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #ANTIBANDING_OFF
29919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
29929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getAntibanding() {
29939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_ANTIBANDING);
29949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
29959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
29969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
29979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the antibanding.
29989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
29993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param antibanding new antibanding value.
30003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
30019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setAntibanding(String antibanding) {
30039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_ANTIBANDING, antibanding);
30049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported antibanding values.
30089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30093f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported antibanding values. null if antibanding
30103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         setting is not supported.
30113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getAntibanding()
30129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedAntibanding() {
30149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX);
30159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
30169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current scene mode setting.
30209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * @return one of SCENE_MODE_XXX string constant. null if scene mode
30229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *         setting is not supported.
30233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_AUTO
30243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_ACTION
30253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PORTRAIT
30263f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_LANDSCAPE
30273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT
30283f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_NIGHT_PORTRAIT
30293f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_THEATRE
30303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_BEACH
30313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SNOW
30323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SUNSET
30333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_STEADYPHOTO
30343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_FIREWORKS
30353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_SPORTS
30363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_PARTY
30373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #SCENE_MODE_CANDLELIGHT
3038da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala         * @see #SCENE_MODE_BARCODE
30399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getSceneMode() {
30419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_SCENE_MODE);
30429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
3045c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * Sets the scene mode. Changing scene mode may override other
3046c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * parameters (such as flash mode, focus mode, white balance). For
3047c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * example, suppose originally flash mode is on and supported flash
3048c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * modes are on/off. In night scene mode, both flash mode and supported
3049c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li         * flash mode may be changed to off. After setting scene mode,
30502988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * applications should call getParameters to know if some parameters are
30512988ab7c322aad7508df930204886f334216b65cWu-cheng Li         * changed.
30529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value scene mode.
30543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
30559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setSceneMode(String value) {
30579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_SCENE_MODE, value);
30589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported scene modes.
30629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported scene modes. null if scene mode setting
30643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
30653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getSceneMode()
30669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedSceneModes() {
30689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX);
30699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
30709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the current flash mode setting.
30749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return current flash mode. null if flash mode setting is not
30763f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         supported.
30773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_OFF
30783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_AUTO
30793f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_ON
30803f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_RED_EYE
30813f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FLASH_MODE_TORCH
30829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public String getFlashMode() {
30849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return get(KEY_FLASH_MODE);
30859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Sets the flash mode.
30899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
30903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value flash mode.
30913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
30929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
30939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public void setFlashMode(String value) {
30949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            set(KEY_FLASH_MODE, value);
30959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
30969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
30979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        /**
30989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         * Gets the supported flash modes.
30999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         *
31003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported flash modes. null if flash mode setting
31013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         is not supported.
31023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFlashMode()
31039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li         */
31049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        public List<String> getSupportedFlashModes() {
31059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX);
31069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return split(str);
31079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
31089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
310936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
311036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the current focus mode setting.
311136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
3112699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * @return current focus mode. This method will always return a non-null
3113699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         value. Applications should call {@link
3114699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         #autoFocus(AutoFocusCallback)} to start the focus if focus
3115699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *         mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
31163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_AUTO
31173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_INFINITY
31183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_MACRO
31193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #FOCUS_MODE_FIXED
3120f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li         * @see #FOCUS_MODE_EDOF
3121d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * @see #FOCUS_MODE_CONTINUOUS_VIDEO
312236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
312336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public String getFocusMode() {
312436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return get(KEY_FOCUS_MODE);
312536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
312636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
312736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
312836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Sets the focus mode.
312936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
31303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @param value focus mode.
31313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
313236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
313336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public void setFocusMode(String value) {
313436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            set(KEY_FOCUS_MODE, value);
313536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
313636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
313736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        /**
313836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         * Gets the supported focus modes.
313936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         *
31403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @return a list of supported focus modes. This method will always
31413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         *         return a list with at least one element.
31423f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li         * @see #getFocusMode()
314336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li         */
314436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        public List<String> getSupportedFocusModes() {
314536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX);
314636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li            return split(str);
314736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li        }
314836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li
314936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
31506c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the focal length (in millimeter) of the camera.
31516c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
31526c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return the focal length. This method will always return a valid
31536c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         value.
31546c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
31556c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getFocalLength() {
31566c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_FOCAL_LENGTH));
31576c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
31586c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
31596c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
31606c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the horizontal angle of view in degrees.
31616c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
31626c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return horizontal angle of view. This method will always return a
31636c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
31646c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
31656c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getHorizontalViewAngle() {
31666c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE));
31676c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
31686c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
31696c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
31706c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * Gets the vertical angle of view in degrees.
31716c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *
31726c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         * @return vertical angle of view. This method will always return a
31736c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         *         valid value.
31746c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li         */
31756c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        public float getVerticalViewAngle() {
31766c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li            return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE));
31776c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        }
31786c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li
31796c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li        /**
318024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the current exposure compensation index.
3181ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
318224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return current exposure compensation index. The range is {@link
318324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMinExposureCompensation} to {@link
318424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         #getMaxExposureCompensation}. 0 means exposure is not
318524b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         adjusted.
3186ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3187ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public int getExposureCompensation() {
318824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_EXPOSURE_COMPENSATION, 0);
3189ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3190ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3191ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
319224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Sets the exposure compensation index.
3193ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
31940402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         * @param value exposure compensation index. The valid value range is
31950402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li         *        from {@link #getMinExposureCompensation} (inclusive) to {@link
319624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        #getMaxExposureCompensation} (inclusive). 0 means exposure is
319724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        not adjusted. Application should call
319824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        getMinExposureCompensation and getMaxExposureCompensation to
319924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *        know if exposure compensation is supported.
3200ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
3201ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        public void setExposureCompensation(int value) {
3202ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li            set(KEY_EXPOSURE_COMPENSATION, value);
3203ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3204ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3205ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
320624b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the maximum exposure compensation index.
3207ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         *
320824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return maximum exposure compensation index (>=0). If both this
320924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMinExposureCompensation} return 0,
321024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
321124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
321224b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMaxExposureCompensation() {
321324b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0);
321424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
321524b326a8978bf78e3e560723dde221792784325bWu-cheng Li
321624b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
321724b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the minimum exposure compensation index.
321824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
321924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return minimum exposure compensation index (<=0). If both this
322024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         method and {@link #getMaxExposureCompensation} return 0,
322124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation is not supported.
3222ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li         */
322324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public int getMinExposureCompensation() {
322424b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0);
322524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
322624b326a8978bf78e3e560723dde221792784325bWu-cheng Li
322724b326a8978bf78e3e560723dde221792784325bWu-cheng Li        /**
322824b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * Gets the exposure compensation step.
322924b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *
323024b326a8978bf78e3e560723dde221792784325bWu-cheng Li         * @return exposure compensation step. Applications can get EV by
323124b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         multiplying the exposure compensation index and step. Ex: if
323224b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         exposure compensation index is -6 and step is 0.333333333, EV
323324b326a8978bf78e3e560723dde221792784325bWu-cheng Li         *         is -2.
323424b326a8978bf78e3e560723dde221792784325bWu-cheng Li         */
323524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        public float getExposureCompensationStep() {
323624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0);
3237ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        }
3238ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li
3239ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li        /**
3240d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-exposure lock state. Applications should check
3241d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method.</p>
32423773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3243d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-exposure routine will immediately
3244d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * pause until the lock is set to false. Exposure compensation settings
3245d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * changes will still take effect while auto-exposure is locked.</p>
3246d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3247d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-exposure is already locked, setting this to true again has
3248d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * no effect (the driver will not recalculate exposure values).</p>
3249d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3250d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3251d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3252b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3253b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock.</p>
3254d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3255b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, auto-exposure lock, and auto-white balance
3256b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * lock can be used to capture an exposure-bracketed burst of images,
3257b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * for example.</p>
3258d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3259d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Auto-exposure state, including the lock state, will not be
32603773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * maintained after camera {@link #release()} is called.  Locking
32613773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * auto-exposure after {@link #open()} but before the first call to
32623773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #startPreview()} will not allow the auto-exposure routine to
3263d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * run at all, and may result in severely over- or under-exposed
3264d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * images.</p>
32653773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
32663773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @param toggle new state of the auto-exposure lock. True means that
32673773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        auto-exposure is locked, false means that the auto-exposure
32683773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *        routine is free to run normally.
32693773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
3270d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoExposureLock()
32713773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
32723773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public void setAutoExposureLock(boolean toggle) {
32733773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE);
32743773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
32753773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
32763773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
32773773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Gets the state of the auto-exposure lock. Applications should check
32783773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #isAutoExposureLockSupported} before using this method. See
32793773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
32803773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
32813773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return State of the auto-exposure lock. Returns true if
3282b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         auto-exposure is currently locked, and false otherwise.
32833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
32843773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
32853773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
32863773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
32873773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean getAutoExposureLock() {
32883773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK);
32893773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
32903773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
32913773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
32923773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
32933773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * Returns true if auto-exposure locking is supported. Applications
32943773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * should call this before trying to lock auto-exposure. See
32953773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * {@link #setAutoExposureLock} for details about the lock.
32963773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
32973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @return true if auto-exposure lock is supported.
32983773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         * @see #setAutoExposureLock(boolean)
32993773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         *
33003773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala         */
33013773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        public boolean isAutoExposureLockSupported() {
33023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
33033773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala            return TRUE.equals(str);
33043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        }
33053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala
33063773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala        /**
3307d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Sets the auto-white balance lock state. Applications should check
3308d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #isAutoWhiteBalanceLockSupported} before using this
3309d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method.</p>
3310d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3311d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If set to true, the camera auto-white balance routine will
3312d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * immediately pause until the lock is set to false.</p>
3313d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3314d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>If auto-white balance is already locked, setting this to true
3315d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * again has no effect (the driver will not recalculate white balance
3316d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * values).</p>
3317d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3318d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * <p>Stopping preview with {@link #stopPreview()}, or triggering still
3319d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * image capture with {@link #takePicture(Camera.ShutterCallback,
3320b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}, will not change the
3321b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * the lock.</p>
3322d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
332316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * <p> Changing the white balance mode with {@link #setWhiteBalance}
332416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * will release the auto-white balance lock if it is set.</p>
332516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         *
3326b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * <p>Exposure compensation, AE lock, and AWB lock can be used to
3327b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * capture an exposure-bracketed burst of images, for example.
3328b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * Auto-white balance state, including the lock state, will not be
3329b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * maintained after camera {@link #release()} is called.  Locking
3330b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * auto-white balance after {@link #open()} but before the first call to
3331b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * {@link #startPreview()} will not allow the auto-white balance routine
3332b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * to run at all, and may result in severely incorrect color in captured
3333b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         * images.</p>
3334d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3335d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @param toggle new state of the auto-white balance lock. True means
3336d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        that auto-white balance is locked, false means that the
3337d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *        auto-white balance routine is free to run normally.
3338d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3339d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #getAutoWhiteBalanceLock()
334016b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala         * @see #setWhiteBalance(String)
3341d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3342d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public void setAutoWhiteBalanceLock(boolean toggle) {
3343d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE);
3344d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3345d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3346d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3347d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Gets the state of the auto-white balance lock. Applications should
3348d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * check {@link #isAutoWhiteBalanceLockSupported} before using this
3349d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * method. See {@link #setAutoWhiteBalanceLock} for details about the
3350d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * lock.
3351d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3352d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return State of the auto-white balance lock. Returns true if
3353d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *         auto-white balance is currently locked, and false
3354b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li         *         otherwise.
3355d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3356d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3357d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3358d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3359d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean getAutoWhiteBalanceLock() {
3360d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK);
3361d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3362d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3363d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3364d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
3365d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * Returns true if auto-white balance locking is supported. Applications
3366d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * should call this before trying to lock auto-white balance. See
3367d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * {@link #setAutoWhiteBalanceLock} for details about the lock.
3368d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3369d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @return true if auto-white balance lock is supported.
3370d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         * @see #setAutoWhiteBalanceLock(boolean)
3371d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         *
3372d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala         */
3373d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        public boolean isAutoWhiteBalanceLockSupported() {
3374d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
3375d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala            return TRUE.equals(str);
3376d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        }
3377d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala
3378d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala        /**
337936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets current zoom value. This also works when smooth zoom is in
33808cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * progress. Applications should check {@link #isZoomSupported} before
33818cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * using this method.
338236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
338336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the current zoom value. The range is 0 to {@link
33848cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom}. 0 means the camera is not zoomed.
338536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
338636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getZoom() {
33878cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_ZOOM, 0);
338836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
338936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
339036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
33918cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Sets current zoom value. If the camera is zoomed (value > 0), the
33928cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * actual picture size may be smaller than picture size setting.
33938cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications can check the actual picture size after picture is
33948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * returned from {@link PictureCallback}. The preview size remains the
33958cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * same in zoom. Applications should check {@link #isZoomSupported}
33968cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * before using this method.
339736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
339836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}.
339936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
340036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public void setZoom(int value) {
34018cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            set(KEY_ZOOM, value);
340236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
340336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
340436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
340536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if zoom is supported. Applications should call this
340636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * before using other zoom methods.
340736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
340836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if zoom is supported.
340936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
341036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isZoomSupported() {
34118cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_ZOOM_SUPPORTED);
34128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
341336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
341436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
341536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
341636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Gets the maximum zoom value allowed for snapshot. This is the maximum
341736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * value that applications can set to {@link #setZoom(int)}.
34188cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Applications should call {@link #isZoomSupported} before using this
34198cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * method. This value may change in different preview size. Applications
34208cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * should call this again after setting preview size.
342136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
342236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return the maximum zoom value supported by the camera.
342336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
342436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public int getMaxZoom() {
34258cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return getInt(KEY_MAX_ZOOM, 0);
342636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
342736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
342836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
34298cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * Gets the zoom ratios of all zoom values. Applications should check
34308cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * {@link #isZoomSupported} before using this method.
343136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
34328cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is
34338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         returned as 320. The number of elements is {@link
34348cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         #getMaxZoom} + 1. The list is sorted from small to large. The
34358cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         first element is always 100. The last element is the zoom
34368cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li         *         ratio of the maximum zoom value.
343736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
34388cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li        public List<Integer> getZoomRatios() {
34398cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return splitInt(get(KEY_ZOOM_RATIOS));
344036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
344136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
344236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        /**
344336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * Returns true if smooth zoom is supported. Applications should call
344436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * this before using other smooth zoom methods.
344536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         *
344636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         * @return true if smooth zoom is supported.
344736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li         */
344836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        public boolean isSmoothZoomSupported() {
34498cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            String str = get(KEY_SMOOTH_ZOOM_SUPPORTED);
34508cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li            return TRUE.equals(str);
345136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li        }
345236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li
3453e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        /**
345432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the distances from the camera to where an object appears to be
3455e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * in focus. The object is sharpest at the optimal focus distance. The
345632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * depth of field is the far focus distance minus near focus distance.</p>
3457e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
345832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus distances may change after calling {@link
3459e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link
3460e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * #startPreview()}. Applications can call {@link #getParameters()}
3461e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * and this method anytime to get the latest focus distances. If the
3462d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li         * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change
346332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * from time to time.</p>
3464699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         *
346532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>This method is intended to estimate the distance between the camera
3466699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * and the subject. After autofocus, the subject distance may be within
3467699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * near and far focus distance. However, the precision depends on the
3468699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li         * camera hardware, autofocus algorithm, the focus area, and the scene.
346932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * The error can be large and it should be only used as a reference.</p>
3470e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
347132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Far focus distance >= optimal focus distance >= near focus distance.
3472185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * If the focus distance is infinity, the value will be
347332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * {@code Float.POSITIVE_INFINITY}.</p>
3474e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *
3475e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         * @param output focus distances in meters. output must be a float
3476e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        array with three elements. Near focus distance, optimal focus
3477e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         *        distance, and far focus distance will be filled in the array.
3478185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_NEAR_INDEX
3479185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_OPTIMAL_INDEX
3480185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li         * @see #FOCUS_DISTANCE_FAR_INDEX
3481e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li         */
3482e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        public void getFocusDistances(float[] output) {
3483e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            if (output == null || output.length != 3) {
3484e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li                throw new IllegalArgumentException(
3485f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa                        "output must be a float array with three elements.");
3486e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3487454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            splitFloat(get(KEY_FOCUS_DISTANCES), output);
3488e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3489e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
349030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
349130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Gets the maximum number of focus areas supported. This is the maximum
34927b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * length of the list in {@link #setFocusAreas(List)} and
34937b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getFocusAreas()}.
349430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
349530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return the maximum number of focus areas supported by the camera.
349630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
349730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
349830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public int getMaxNumFocusAreas() {
349930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0);
350030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
350130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
350230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
350332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current focus areas. Camera driver uses the areas to decide
350432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus.</p>
350530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
350632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setFocusAreas(List)}, apps should
35077b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumFocusAreas()} to know the maximum number of
350832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * focus areas first. If the value is 0, focus area is not supported.</p>
350930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
351032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each focus area is a rectangle with specified weight. The direction
351130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * is relative to the sensor orientation, that is, what the sensor sees.
351230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * The direction is not affected by the rotation or mirroring of
351330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle
351430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * range from -1000 to 1000. (-1000, -1000) is the upper left point.
3515bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * (1000, 1000) is the lower right point. The width and height of focus
351632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * areas cannot be 0 or negative.</p>
351730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
351832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000. The weight should be
35194e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * interpreted as a per-pixel weight - all pixels in the area have the
35204e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * specified weight. This means a small area with the same weight as a
35214e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * larger area will have less influence on the focusing than the larger
35224e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * area. Focus areas can partially overlap and the driver will add the
352332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * weights in the overlap region.</p>
352430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
352532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} focus area list means the driver is
352632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * free to select focus targets as it wants. For example, the driver may
352732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * use more signals to select focus areas and change them
352832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * dynamically. Apps can set the focus area list to {@code null} if they
352932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * want the driver to completely control focusing.</p>
353030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
353132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus areas are relative to the current field of view
353230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
353330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * represents the top of the currently visible camera frame. The focus
353430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * area cannot be set to be outside the current field of view, even
353532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * when using zoom.</p>
353630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
353732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Focus area only has effect if the current focus mode is
353853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO},
353953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or
354053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li         * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p>
354130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
354230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @return a list of current focus areas
354330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
354430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        public List<Area> getFocusAreas() {
3545f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            return splitArea(get(KEY_FOCUS_AREAS));
354630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
354730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
354830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        /**
354930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * Sets focus areas. See {@link #getFocusAreas()} for documentation.
355030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         *
35517b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param focusAreas the focus areas
355230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         * @see #getFocusAreas()
355330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li         */
3554e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setFocusAreas(List<Area> focusAreas) {
3555e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_FOCUS_AREAS, focusAreas);
3556e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3557e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3558e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3559e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Gets the maximum number of metering areas supported. This is the
35607b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * maximum length of the list in {@link #setMeteringAreas(List)} and
35617b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * {@link #getMeteringAreas()}.
3562e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3563e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return the maximum number of metering areas supported by the camera.
3564e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3565e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3566e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public int getMaxNumMeteringAreas() {
3567e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            return getInt(KEY_MAX_NUM_METERING_AREAS, 0);
3568e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3569e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3570e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
357132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Gets the current metering areas. Camera driver uses these areas to
357232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * decide exposure.</p>
3573e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
357432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should
35757b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * call {@link #getMaxNumMeteringAreas()} to know the maximum number of
35767b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * metering areas first. If the value is 0, metering area is not
357732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * supported.</p>
3578e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
357932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Each metering area is a rectangle with specified weight. The
3580e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * direction is relative to the sensor orientation, that is, what the
3581e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * sensor sees. The direction is not affected by the rotation or
3582e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the
3583e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left
3584bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li         * point. (1000, 1000) is the lower right point. The width and height of
358532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * metering areas cannot be 0 or negative.</p>
3586e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
358732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>The weight must range from 1 to 1000, and represents a weight for
35884e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * every pixel in the area. This means that a large metering area with
35894e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * the same weight as a smaller area will have more effect in the
35904e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala         * metering result.  Metering areas can partially overlap and the driver
359132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * will add the weights in the overlap region.</p>
3592e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
359332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>A special case of a {@code null} metering area list means the driver
359432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * is free to meter as it chooses. For example, the driver may use more
359532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * signals to select metering areas and change them dynamically. Apps
359632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * can set the metering area list to {@code null} if they want the
359732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * driver to completely control metering.</p>
3598e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
359932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>Metering areas are relative to the current field of view
3600e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000)
3601e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * represents the top of the currently visible camera frame. The
3602e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * metering area cannot be set to be outside the current field of view,
360332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * even when using zoom.</p>
3604e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
360532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * <p>No matter what metering areas are, the final exposure are compensated
360632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala         * by {@link #setExposureCompensation(int)}.</p>
3607e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
3608e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @return a list of current metering areas
3609e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3610e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public List<Area> getMeteringAreas() {
3611d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li            return splitArea(get(KEY_METERING_AREAS));
3612e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        }
3613e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li
3614e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        /**
3615e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * Sets metering areas. See {@link #getMeteringAreas()} for
3616e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * documentation.
3617e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         *
36187b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li         * @param meteringAreas the metering areas
3619e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         * @see #getMeteringAreas()
3620e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li         */
3621e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li        public void setMeteringAreas(List<Area> meteringAreas) {
3622e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li            set(KEY_METERING_AREAS, meteringAreas);
362330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
362430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
36254c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        /**
36264c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * Gets the maximum number of detected faces supported. This is the
36274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * maximum length of the list returned from {@link FaceDetectionListener}.
36284c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * If the return value is 0, face detection of the specified type is not
36294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * supported.
36304c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         *
36314c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         * @return the maximum number of detected face supported by the camera.
3632464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez         * @see #startFaceDetection()
36334c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li         */
3634c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li        public int getMaxNumDetectedFaces() {
3635c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li            return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0);
36364c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li        }
36374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li
363825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        /**
36399c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Sets recording mode hint. This tells the camera that the intent of
36409c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * the application is to record videos {@link
36419c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * android.media.MediaRecorder#start()}, not to take still pictures
36429c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback,
36439c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can
36449c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * allow MediaRecorder.start() to start faster or with fewer glitches on
36459c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * output. This should be called before starting preview for the best
36469c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * result, but can be changed while the preview is active. The default
36479c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * value is false.
36489c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
36499c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * The app can still call takePicture() when the hint is true or call
36509c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * MediaRecorder.start() when the hint is false. But the performance may
36519c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * be worse.
36529c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         *
36539c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li         * @param hint true if the apps intend to record videos using
365425d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         *             {@link android.media.MediaRecorder}.
365525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li         */
365625d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        public void setRecordingHint(boolean hint) {
365725d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li            set(KEY_RECORDING_HINT, hint ? TRUE : FALSE);
365825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li        }
365925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li
366098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        /**
36611cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Returns true if video snapshot is supported. That is, applications
366298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * can call {@link #takePicture(Camera.ShutterCallback,
36631cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback, Camera.PictureCallback,
36641cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * Camera.PictureCallback)} during recording. Applications do not need
36651cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * to call {@link #startPreview()} after taking a picture. The preview
36661cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * will be still active. Other than that, taking a picture during
36671cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * recording is identical to taking a picture normally. All settings and
36681cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * methods related to takePicture work identically. Ex:
36691cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()},
36701cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The
36711cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and
36721cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * {@link #FLASH_MODE_ON} also still work, but the video will record the
36731cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * flash.</p>
36741cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         *
36751cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Applications can set shutter callback as null to avoid the shutter
367698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * sound. It is also recommended to set raw picture and post view
36771cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * callbacks to null to avoid the interrupt of preview display.</p>
367898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
36791cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * <p>Field-of-view of the recorded video may be different from that of the
36801cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * captured pictures. The maximum size of a video snapshot may be
36811cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * smaller than that for regular still captures. If the current picture
36821cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * size is set higher than can be supported by video snapshot, the
36831cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala         * picture will be captured at the maximum supported size instead.</p>
368498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         *
368598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         * @return true if video snapshot is supported.
368698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li         */
368798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        public boolean isVideoSnapshotSupported() {
368898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED);
368998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li            return TRUE.equals(str);
369098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li        }
369198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li
3692037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3693037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Enables and disables video stabilization. Use
3694037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #isVideoStabilizationSupported} to determine if calling this
3695037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * method is valid.</p>
3696037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3697037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization reduces the shaking due to the motion of the
3698037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * camera in both the preview stream and in recorded videos, including
3699037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * data received from the preview callback. It does not reduce motion
3700037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * blur in images captured with
3701037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link Camera#takePicture takePicture}.</p>
3702037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3703037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * <p>Video stabilization can be enabled and disabled while preview or
3704037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * recording is active, but toggling it may cause a jump in the video
3705037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * stream that may be undesirable in a recorded video.</p>
3706037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3707037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @param toggle Set to true to enable video stabilization, and false to
3708037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * disable video stabilization.
3709037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
3710037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
3711037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3712037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public void setVideoStabilization(boolean toggle) {
3713037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE);
3714037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3715037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
3716037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3717037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Get the current state of video stabilization. See
3718037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
3719037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3720037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is enabled
3721037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #isVideoStabilizationSupported()
3722037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
3723037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3724037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean getVideoStabilization() {
3725037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION);
3726037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
3727037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3728037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
3729037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        /**
3730037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * Returns true if video stabilization is supported. See
3731037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * {@link #setVideoStabilization} for details of video stabilization.
3732037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         *
3733037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @return true if video stabilization is supported
3734037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #setVideoStabilization(boolean)
3735037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         * @see #getVideoStabilization()
3736037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala         */
3737037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        public boolean isVideoStabilizationSupported() {
3738037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED);
3739037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala            return TRUE.equals(str);
3740037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala        }
3741037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala
37429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of String.
37439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
37449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<String> split(String str) {
37459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
37469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
37470a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
37480a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
37499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<String> substrings = new ArrayList<String>();
37500a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
37510a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(s);
37529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
37539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
37549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
37559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
37569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Integer.
37579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
37589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Integer> splitInt(String str) {
37599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
37609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
37610a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
37620a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
37639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Integer> substrings = new ArrayList<Integer>();
37640a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
37650a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                substrings.add(Integer.parseInt(s));
37669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
37679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (substrings.size() == 0) return null;
37689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return substrings;
37699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
37709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
3771454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitInt(String str, int[] output) {
3772454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
3773454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
37740a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
37750a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
3776454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
37770a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
37780a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Integer.parseInt(s);
3779454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
3780454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
3781454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3782e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        // Splits a comma delimited string to an ArrayList of Float.
3783454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private void splitFloat(String str, float[] output) {
3784454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null) return;
3785e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
37860a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
37870a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
3788454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int index = 0;
37890a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
37900a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                output[index++] = Float.parseFloat(s);
3791e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li            }
3792e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li        }
3793e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li
379424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a float parameter.
379524b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private float getFloat(String key, float defaultValue) {
379624b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
379724b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Float.parseFloat(mMap.get(key));
379824b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
379924b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
380024b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
380124b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
380224b326a8978bf78e3e560723dde221792784325bWu-cheng Li
380324b326a8978bf78e3e560723dde221792784325bWu-cheng Li        // Returns the value of a integer parameter.
380424b326a8978bf78e3e560723dde221792784325bWu-cheng Li        private int getInt(String key, int defaultValue) {
380524b326a8978bf78e3e560723dde221792784325bWu-cheng Li            try {
380624b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return Integer.parseInt(mMap.get(key));
380724b326a8978bf78e3e560723dde221792784325bWu-cheng Li            } catch (NumberFormatException ex) {
380824b326a8978bf78e3e560723dde221792784325bWu-cheng Li                return defaultValue;
380924b326a8978bf78e3e560723dde221792784325bWu-cheng Li            }
381024b326a8978bf78e3e560723dde221792784325bWu-cheng Li        }
381124b326a8978bf78e3e560723dde221792784325bWu-cheng Li
38129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Splits a comma delimited string to an ArrayList of Size.
38139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null or the size is 0.
38149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private ArrayList<Size> splitSize(String str) {
38159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
38169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
38170a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
38180a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            splitter.setString(str);
38199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            ArrayList<Size> sizeList = new ArrayList<Size>();
38200a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen            for (String s : splitter) {
38210a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen                Size size = strToSize(s);
38229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                if (size != null) sizeList.add(size);
38239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
38249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (sizeList.size() == 0) return null;
38259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return sizeList;
38269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
38279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
38289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Parses a string (ex: "480x320") to Size object.
38299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        // Return null if the passing string is null.
38309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        private Size strToSize(String str) {
38319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (str == null) return null;
38329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li
38339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            int pos = str.indexOf('x');
38349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            if (pos != -1) {
38359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String width = str.substring(0, pos);
38369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                String height = str.substring(pos + 1);
38379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                return new Size(Integer.parseInt(width),
38389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li                                Integer.parseInt(height));
38399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            }
38409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            Log.e(TAG, "Invalid size parameter string=" + str);
38419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li            return null;
38429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li        }
3843454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3844454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Splits a comma delimited string to an ArrayList of int array.
3845454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // Example string: "(10000,26623),(10000,30000)". Return null if the
3846454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        // passing string is null or the size is 0.
3847454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        private ArrayList<int[]> splitRange(String str) {
3848454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (str == null || str.charAt(0) != '('
3849454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
3850454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                Log.e(TAG, "Invalid range list string=" + str);
3851454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                return null;
3852454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            }
3853454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3854454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            ArrayList<int[]> rangeList = new ArrayList<int[]>();
3855454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            int endIndex, fromIndex = 1;
3856454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            do {
3857454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                int[] range = new int[2];
3858454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
3859454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
3860454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                splitInt(str.substring(fromIndex, endIndex), range);
3861454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                rangeList.add(range);
3862454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li                fromIndex = endIndex + 3;
3863454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            } while (endIndex != str.length() - 1);
3864454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li
3865454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            if (rangeList.size() == 0) return null;
3866454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li            return rangeList;
3867454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li        }
386830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
386930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Splits a comma delimited string to an ArrayList of Area objects.
387030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if
3871f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li        // the passing string is null or the size is 0 or (0,0,0,0,0).
387230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        private ArrayList<Area> splitArea(String str) {
387330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (str == null || str.charAt(0) != '('
387430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                    || str.charAt(str.length() - 1) != ')') {
387530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Log.e(TAG, "Invalid area string=" + str);
387630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                return null;
387730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            }
387830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
387930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            ArrayList<Area> result = new ArrayList<Area>();
388030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int endIndex, fromIndex = 1;
388130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            int[] array = new int[5];
388230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            do {
388330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                endIndex = str.indexOf("),(", fromIndex);
388430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                if (endIndex == -1) endIndex = str.length() - 1;
388530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                splitInt(str.substring(fromIndex, endIndex), array);
388630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                Rect rect = new Rect(array[0], array[1], array[2], array[3]);
388730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                result.add(new Area(rect, array[4]));
388830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li                fromIndex = endIndex + 3;
388930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            } while (endIndex != str.length() - 1);
389030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li
389130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            if (result.size() == 0) return null;
3892f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
3893f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            if (result.size() == 1) {
3894bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li                Area area = result.get(0);
3895f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                Rect rect = area.rect;
3896f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                if (rect.left == 0 && rect.top == 0 && rect.right == 0
3897f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                        && rect.bottom == 0 && area.weight == 0) {
3898f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                    return null;
3899f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li                }
3900f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li            }
3901f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li
390230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li            return result;
390330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li        }
3904b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li
3905b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        private boolean same(String s1, String s2) {
3906b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 == null && s2 == null) return true;
3907b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            if (s1 != null && s1.equals(s2)) return true;
3908b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li            return false;
3909b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li        }
39109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    };
39119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
3912