Camera.java revision 7d9a8ffd08fa950eb14f8224f6090fe46ab4aa9f
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; 487d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkinimport java.util.LinkedHashMap; 49bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Liimport java.util.List; 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"><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> <uses-permission android:name="android.permission.CAMERA" /> 64df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <uses-feature android:name="android.hardware.camera" /> 65df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <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 1544838e338129e09a37b8c8ad5e44f85ec5cd3aea1Ashok Bhat private long 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"><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"><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 21537d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin /** 21547d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * Order matters: Keys that are {@link #set(String, String) set} later 21557d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * will take precedence over keys that are set earlier (if the two keys 21567d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * conflict with each other). 21577d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * 21587d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it 21597d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later 21607d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * is the one that will take precedence. 21617d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * </p> 21627d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin */ 21637d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin private final LinkedHashMap<String, String> mMap; 21649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Parameters() { 21667d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64); 21679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Writes the current Parameters to the log. 21719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @hide 21729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @deprecated 21739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void dump() { 21759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "dump: size=" + mMap.size()); 21769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project for (String k : mMap.keySet()) { 21779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); 21789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Creates a single string with all the parameters set in 21839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this Parameters object. 21849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>The {@link #unflatten(String)} method does the reverse.</p> 21859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 21869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return a String with all values from this Parameters object, in 21879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * semi-colon delimited key-value pairs 21889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String flatten() { 21900a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen StringBuilder flattened = new StringBuilder(128); 21919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project for (String k : mMap.keySet()) { 21929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(k); 21939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append("="); 21949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(mMap.get(k)); 21959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(";"); 21969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // chop off the extra semicolon at the end 21989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.deleteCharAt(flattened.length()-1); 21999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return flattened.toString(); 22009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Takes a flattened string of parameters and adds each one to 22049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this Parameters object. 22059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>The {@link #flatten()} method does the reverse.</p> 22069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param flattened a String of parameters (key-value paired) that 22089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * are semi-colon delimited 22099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void unflatten(String flattened) { 22119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.clear(); 22129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 22130a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); 22140a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(flattened); 22150a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String kv : splitter) { 22169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int pos = kv.indexOf('='); 22179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pos == -1) { 22189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project continue; 22199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String k = kv.substring(0, pos); 22219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = kv.substring(pos + 1); 22229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.put(k, v); 22239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 22269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void remove(String key) { 22279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.remove(key); 22289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets a String parameter. 22329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 22349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param value the String value of the parameter 22359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void set(String key, String value) { 2237cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) { 2238cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)"); 22399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 22409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2241cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) { 2242cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)"); 22439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 22449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22467d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin put(key, value); 22479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets an integer parameter. 22519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 22539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param value the int value of the parameter 22549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void set(String key, int value) { 22567d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin put(key, Integer.toString(value)); 22577d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin } 22587d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin 22597d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin private void put(String key, String value) { 22607d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin /* 22617d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * Remove the key if it already exists. 22627d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * 22637d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * This way setting a new value for an already existing key will always move 22647d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * that key to be ordered the latest in the map. 22657d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin */ 22667d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap.remove(key); 22677d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap.put(key, value); 22689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2270e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li private void set(String key, List<Area> areas) { 2271f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (areas == null) { 2272f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li set(key, "(0,0,0,0,0)"); 2273f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } else { 2274f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li StringBuilder buffer = new StringBuilder(); 2275f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li for (int i = 0; i < areas.size(); i++) { 2276f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Area area = areas.get(i); 2277f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Rect rect = area.rect; 2278f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append('('); 2279f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.left); 2280f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2281f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.top); 2282f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2283f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.right); 2284f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2285f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.bottom); 2286f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2287f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(area.weight); 2288f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(')'); 2289f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (i != areas.size() - 1) buffer.append(','); 2290f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 2291f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li set(key, buffer.toString()); 2292e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 2293e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 2294e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 22959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the value of a String parameter. 22979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 22999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the String value of the parameter 23009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String get(String key) { 23029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mMap.get(key); 23039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the value of an integer parameter. 23079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 23089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 23099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the int value of the parameter 23109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getInt(String key) { 23129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return Integer.parseInt(mMap.get(key)); 23139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 231626274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * Sets the dimensions for preview pictures. If the preview has already 231726274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * started, applications should stop the preview first before changing 231826274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * preview size. 23199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 2320c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * The sides of width and height are based on camera orientation. That 2321c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * is, the preview size is the size before it is rotated by display 2322c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * orientation. So applications need to consider the display orientation 2323c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * while setting preview size. For example, suppose the camera supports 2324c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * both 480x320 and 320x480 preview sizes. The application wants a 3:2 2325c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * preview ratio. If the display orientation is set to 0 or 180, preview 2326c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * size should be set to 480x320. If the display orientation is set to 2327c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 90 or 270, preview size should be set to 320x480. The display 2328c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * orientation should also be considered while setting picture size and 2329c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * thumbnail size. 2330c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 23319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the pictures, in pixels 23329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the pictures, in pixels 2333c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setDisplayOrientation(int) 2334c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #getCameraInfo(int, CameraInfo) 2335c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPictureSize(int, int) 2336c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setJpegThumbnailSize(int, int) 23379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewSize(int width, int height) { 23399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = Integer.toString(width) + "x" + Integer.toString(height); 23409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_SIZE, v); 23419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the dimensions setting for preview pictures. 23459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 2346dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return a Size object with the width and height setting 23479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for the preview picture 23489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Size getPreviewSize() { 23509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String pair = get(KEY_PREVIEW_SIZE); 23519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return strToSize(pair); 23529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 23539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 23559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported preview sizes. 23569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 23573f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of Size object. This method will always return a list 23589c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li * with at least one element. 23599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 23609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Size> getSupportedPreviewSizes() { 23619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); 23629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitSize(str); 23639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 236632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the supported video frame sizes that can be used by 236732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * MediaRecorder.</p> 2368dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 236932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>If the returned list is not null, the returned list will contain at 2370dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * least one Size and one of the sizes in the returned list must be 2371dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * passed to MediaRecorder.setVideoSize() for camcorder application if 2372dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * camera is used as the video source. In this case, the size of the 2373dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preview can be different from the resolution of the recorded video 237432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * during video recording.</p> 2375dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 2376dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return a list of Size object if camera has separate preview and 2377dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video output; otherwise, null is returned. 2378dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @see #getPreferredPreviewSizeForVideo() 2379dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong */ 2380dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong public List<Size> getSupportedVideoSizes() { 2381dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); 2382dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong return splitSize(str); 2383dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong } 2384dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong 2385dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong /** 2386dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * Returns the preferred or recommended preview size (width and height) 2387dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * in pixels for video recording. Camcorder applications should 2388dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * set the preview size to a value that is not larger than the 2389dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preferred preview size. In other words, the product of the width 2390dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * and height of the preview size should not be larger than that of 2391dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * the preferred preview size. In addition, we recommend to choose a 2392dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preview size that has the same aspect ratio as the resolution of 2393dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video to be recorded. 2394dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 2395dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return the preferred preview size (width and height) in pixels for 2396dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video recording if getSupportedVideoSizes() does not return 2397dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * null; otherwise, null is returned. 2398dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @see #getSupportedVideoSizes() 2399dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong */ 2400dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong public Size getPreferredPreviewSizeForVideo() { 2401dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); 2402dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong return strToSize(pair); 2403dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong } 2404dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong 2405dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong /** 240632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If 24074c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * applications set both width and height to 0, EXIF will not contain 240832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * thumbnail.</p> 24099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 241032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Applications need to consider the display orientation. See {@link 241132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * #setPreviewSize(int,int)} for reference.</p> 2412c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 24139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the thumbnail, in pixels 24149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the thumbnail, in pixels 2415c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPreviewSize(int,int) 24169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 24179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegThumbnailSize(int width, int height) { 24189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_WIDTH, width); 24199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_HEIGHT, height); 24209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 24219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 24229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 24239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the dimensions for EXIF thumbnail in Jpeg picture. 24249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return a Size object with the height and width setting for the EXIF 24269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * thumbnails 24279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public Size getJpegThumbnailSize() { 24299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), 24309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); 24319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24344c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * Gets the supported jpeg thumbnail sizes. 24354c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * 24363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of Size object. This method will always return a list 24374c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * with at least two elements. Size 0,0 (no thumbnail) is always 24384c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * supported. 24394c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li */ 24404c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li public List<Size> getSupportedJpegThumbnailSizes() { 24414c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); 24424c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li return splitSize(str); 24434c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li } 24444c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li 24454c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li /** 24469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the quality of the EXIF thumbnail in Jpeg picture. 24479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 24499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * to 100, with 100 being the best. 24509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegThumbnailQuality(int quality) { 24529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_QUALITY, quality); 24539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the quality setting for the EXIF thumbnail in Jpeg picture. 24579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return the JPEG quality setting of the EXIF thumbnail. 24599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public int getJpegThumbnailQuality() { 24619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_JPEG_THUMBNAIL_QUALITY); 24629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets Jpeg quality of captured picture. 24669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param quality the JPEG quality of captured picture. The range is 1 24689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * to 100, with 100 being the best. 24699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 24709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegQuality(int quality) { 24719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_QUALITY, quality); 24729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 24739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 24749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 24759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the quality setting for the JPEG picture. 24769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 24779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return the JPEG picture quality setting. 24789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public int getJpegQuality() { 24809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_JPEG_QUALITY); 24819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2484a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * Sets the rate at which preview frames are received. This is the 2485a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * target frame rate. The actual frame rate depends on the driver. 24869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 24879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fps the frame rate (frames per second) 24885f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} 24899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24905f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 24919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewFrameRate(int fps) { 24929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_FRAME_RATE, fps); 24939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2496a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * Returns the setting for the rate at which preview frames are 2497a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * received. This is the target frame rate. The actual frame rate 2498a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * depends on the driver. 24999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the frame rate setting (frames per second) 25015f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #getPreviewFpsRange(int[])} 25029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 25035f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 25049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPreviewFrameRate() { 25059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_PREVIEW_FRAME_RATE); 25069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 25079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 25089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 25099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported preview frame rates. 25109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported preview frame rates. null if preview 25123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * frame rate setting is not supported. 25135f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} 25149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 25155f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 25169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPreviewFrameRates() { 25179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); 25189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitInt(str); 25199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 25219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 25224a68e3c26dd2512c319071dc20074baa6e7d171fHai Guo * Sets the minimum and maximum preview fps. This controls the rate of 25231620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li * preview frames received in {@link PreviewCallback}. The minimum and 2524454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * maximum preview fps must be one of the elements from {@link 2525454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getSupportedPreviewFpsRange}. 2526454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2527454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @param min the minimum preview fps (scaled by 1000). 2528454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @param max the maximum preview fps (scaled by 1000). 2529454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @throws RuntimeException if fps range is invalid. 2530454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) 2531454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #getSupportedPreviewFpsRange() 2532454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2533454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public void setPreviewFpsRange(int min, int max) { 2534454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); 2535454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2536454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2537454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 2538454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * Returns the current minimum and maximum preview fps. The values are 2539454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * one of the elements returned by {@link #getSupportedPreviewFpsRange}. 2540454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2541454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @return range the minimum and maximum preview fps (scaled by 1000). 2542454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MIN_INDEX 2543454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MAX_INDEX 2544454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #getSupportedPreviewFpsRange() 2545454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2546454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public void getPreviewFpsRange(int[] range) { 2547454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (range == null || range.length != 2) { 2548454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li throw new IllegalArgumentException( 25495f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li "range must be an array with two elements."); 2550454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2551454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitInt(get(KEY_PREVIEW_FPS_RANGE), range); 2552454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2553454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2554454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 2555454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * Gets the supported preview fps (frame-per-second) ranges. Each range 2556454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * contains a minimum fps and maximum fps. If minimum fps equals to 2557454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * maximum fps, the camera outputs frames in fixed frame rate. If not, 2558454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * the camera outputs frames in auto frame rate. The actual frame rate 2559454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * fluctuates between the minimum and the maximum. The values are 2560454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * multiplied by 1000 and represented in integers. For example, if frame 2561454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * rate is 26.623 frames per second, the value is 26623. 2562454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2563454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @return a list of supported preview fps ranges. This method returns a 2564454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * list with at least one element. Every element is an int array 2565454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * of two values - minimum fps and maximum fps. The list is 2566454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * sorted from small to large (first by maximum fps and then 2567454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * minimum fps). 2568454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MIN_INDEX 2569454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MAX_INDEX 2570454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2571454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public List<int[]> getSupportedPreviewFpsRange() { 2572454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); 2573454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return splitRange(str); 2574454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2575454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2576454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 25777478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * Sets the image format for preview pictures. 2578da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main * <p>If this is never called, the default format will be 2579a696f5d667227365da732481770767dcb330dd23Mathias Agopian * {@link android.graphics.ImageFormat#NV21}, which 2580df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * uses the NV21 encoding format.</p> 25817478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * 2582951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of 2583951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * the available preview formats. 2584951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2585951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>It is strongly recommended that either 2586951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#NV21} or 2587951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#YV12} is used, since 2588951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * they are supported by all camera devices.</p> 2589951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2590951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>For YV12, the image buffer that is received is not necessarily 2591951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * tightly packed, as there may be padding at the end of each row of 2592951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * pixel data, as described in 2593951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#YV12}. For camera callback data, 2594951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * it can be assumed that the stride of the Y and UV data is the 2595951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * smallest possible that meets the alignment requirements. That is, if 2596951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * the preview size is <var>width x height</var>, then the following 2597951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * equations describe the buffer index for the beginning of row 2598951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>y</var> for the Y plane and row <var>c</var> for the U and V 2599951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * planes: 2600951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2601951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@code 2602951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <pre> 2603951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * yStride = (int) ceil(width / 16.0) * 16; 2604951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16; 2605951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * ySize = yStride * height; 2606951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uvSize = uvStride * height / 2; 2607951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * yRowIndex = yStride * y; 2608951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uRowIndex = ySize + uvSize + uvStride * c; 2609951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * vRowIndex = ySize + uvStride * c; 2610951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * size = ySize + uvSize * 2;</pre> 2611951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * } 2612951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2613951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @param pixel_format the desired preview picture format, defined by 2614951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * one of the {@link android.graphics.ImageFormat} constants. (E.g., 2615951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>ImageFormat.NV21</var> (default), or 2616951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>ImageFormat.YV12</var>) 2617951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2618a696f5d667227365da732481770767dcb330dd23Mathias Agopian * @see android.graphics.ImageFormat 2619951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats 26209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewFormat(int pixel_format) { 26229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String s = cameraFormatForPixelFormat(pixel_format); 26239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (s == null) { 26249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 26259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid pixel_format=" + pixel_format); 26269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_FORMAT, s); 26299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 26323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * Returns the image format for preview frames got from 26339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * {@link PreviewCallback}. 26347478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * 26353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return the preview format. 26363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 2637951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see #setPreviewFormat 26389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPreviewFormat() { 26409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); 26419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 26429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 26439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 2644f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} 2645f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * is always supported. {@link android.graphics.ImageFormat#YV12} 2646f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * is always supported since API level 12. 26479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 26483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported preview formats. This method will always 26493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 26503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 2651951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see #setPreviewFormat 26529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 26539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPreviewFormats() { 26549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); 2655eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang ArrayList<Integer> formats = new ArrayList<Integer>(); 2656eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang for (String s : split(str)) { 2657eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang int f = pixelFormatForCameraFormat(s); 2658a696f5d667227365da732481770767dcb330dd23Mathias Agopian if (f == ImageFormat.UNKNOWN) continue; 2659eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang formats.add(f); 2660eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang } 2661eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang return formats; 26629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 266532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Sets the dimensions for pictures.</p> 26669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 266732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Applications need to consider the display orientation. See {@link 266832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * #setPreviewSize(int,int)} for reference.</p> 2669c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 26709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width for pictures, in pixels 26719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height for pictures, in pixels 2672c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPreviewSize(int,int) 2673c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 26749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPictureSize(int width, int height) { 26769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = Integer.toString(width) + "x" + Integer.toString(height); 26779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PICTURE_SIZE, v); 26789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 26819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the dimension setting for pictures. 26829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 26839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return a Size object with the height and width setting 26849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for pictures 26859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Size getPictureSize() { 26879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String pair = get(KEY_PICTURE_SIZE); 26889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return strToSize(pair); 26899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 26909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 26929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported picture sizes. 26939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 26943f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported picture sizes. This method will always 26953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 26969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 26979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Size> getSupportedPictureSizes() { 26989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); 26999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitSize(str); 27009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 27039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the image format for pictures. 27049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param pixel_format the desired picture format 2706a696f5d667227365da732481770767dcb330dd23Mathias Agopian * (<var>ImageFormat.NV21</var>, 2707a696f5d667227365da732481770767dcb330dd23Mathias Agopian * <var>ImageFormat.RGB_565</var>, or 2708a696f5d667227365da732481770767dcb330dd23Mathias Agopian * <var>ImageFormat.JPEG</var>) 2709a696f5d667227365da732481770767dcb330dd23Mathias Agopian * @see android.graphics.ImageFormat 27109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPictureFormat(int pixel_format) { 27129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String s = cameraFormatForPixelFormat(pixel_format); 27139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (s == null) { 27149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 27159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid pixel_format=" + pixel_format); 27169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PICTURE_FORMAT, s); 27199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 27229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the image format for pictures. 27239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return the picture format 27253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 27269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPictureFormat() { 27289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); 27299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 27309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 27319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 27329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported picture formats. 27339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return supported picture formats. This method will always return a 27353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * list with at least one element. 27363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 27379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 27389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPictureFormats() { 27399c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); 27409c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li ArrayList<Integer> formats = new ArrayList<Integer>(); 27419c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li for (String s : split(str)) { 27429c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li int f = pixelFormatForCameraFormat(s); 2743a696f5d667227365da732481770767dcb330dd23Mathias Agopian if (f == ImageFormat.UNKNOWN) continue; 27449c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li formats.add(f); 27459c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li } 27469c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li return formats; 27479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private String cameraFormatForPixelFormat(int pixel_format) { 27509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(pixel_format) { 2751a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; 2752a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; 2753a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; 275410a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; 2755a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; 2756a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; 275770fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB; 2758a696f5d667227365da732481770767dcb330dd23Mathias Agopian default: return null; 27599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private int pixelFormatForCameraFormat(String format) { 27639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (format == null) 2764a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.UNKNOWN; 27659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV422SP)) 2767a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.NV16; 27689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV420SP)) 2770a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.NV21; 27719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2772eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang if (format.equals(PIXEL_FORMAT_YUV422I)) 2773a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.YUY2; 2774eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang 277510a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV420P)) 277610a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li return ImageFormat.YV12; 277710a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li 27789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_RGB565)) 2779a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.RGB_565; 27809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_JPEG)) 2782a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.JPEG; 27839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2784a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.UNKNOWN; 27859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 27888969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * Sets the clockwise rotation angle in degrees relative to the 27898969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * orientation of the camera. This affects the pictures returned from 27908969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * JPEG {@link PictureCallback}. The camera driver may set orientation 27918969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * in the EXIF header without rotating the picture. Or the driver may 27928969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * rotate the picture and the EXIF thumbnail. If the Jpeg picture is 2793a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * rotated, the orientation in the EXIF header will be missing or 1 (row 2794a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * #0 is top and column #0 is left side). 2795a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * 2796a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * <p> 2797a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * If applications want to rotate the picture to match the orientation 2798a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * of what users see, apps should use 2799a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * {@link android.view.OrientationEventListener} and 2800a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * {@link android.hardware.Camera.CameraInfo}. The value from 2801a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * OrientationEventListener is relative to the natural orientation of 2802a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * the device. CameraInfo.orientation is the angle between camera 2803a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * orientation and natural device orientation. The sum of the two is the 2804a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * rotation angle for back-facing camera. The difference of the two is 2805a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * the rotation angle for front-facing camera. Note that the JPEG 2806a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * pictures of front-facing cameras are not mirrored as in preview 2807a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * display. 2808a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * 2809a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * <p> 2810a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * For example, suppose the natural orientation of the device is 28112fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * portrait. The device is rotated 270 degrees clockwise, so the device 28122fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * orientation is 270. Suppose a back-facing camera sensor is mounted in 28132fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * landscape and the top side of the camera sensor is aligned with the 28142fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * right edge of the display in natural orientation. So the camera 28152fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * orientation is 90. The rotation should be set to 0 (270 + 90). 28162fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 281769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * <p>The reference code is as follows. 28182fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 2819e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala * <pre> 28209a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main * public void onOrientationChanged(int orientation) { 28212fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * if (orientation == ORIENTATION_UNKNOWN) return; 28222fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * android.hardware.Camera.CameraInfo info = 28232fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * new android.hardware.Camera.CameraInfo(); 28242fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * android.hardware.Camera.getCameraInfo(cameraId, info); 28252fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * orientation = (orientation + 45) / 90 * 90; 28262fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * int rotation = 0; 28272fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { 28282fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * rotation = (info.orientation - orientation + 360) % 360; 28292fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } else { // back-facing camera 28302fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * rotation = (info.orientation + orientation) % 360; 28312fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } 28322fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * mParameters.setRotation(rotation); 28332fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * } 2834e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala * </pre> 28352fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 28362fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * @param rotation The rotation angle in degrees relative to the 28372fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * orientation of the camera. Rotation can only be 0, 28382fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 90, 180 or 270. 28399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @throws IllegalArgumentException if rotation value is invalid. 28409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @see android.view.OrientationEventListener 28412fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * @see #getCameraInfo(int, CameraInfo) 28429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setRotation(int rotation) { 28449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (rotation == 0 || rotation == 90 || rotation == 180 28459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li || rotation == 270) { 28469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_ROTATION, Integer.toString(rotation)); 28479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } else { 28489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 28499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid rotation=" + rotation); 28509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS latitude coordinate. This will be stored in JPEG EXIF 28559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * header. 28569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 28579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param latitude GPS latitude coordinate. 28589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsLatitude(double latitude) { 28609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_LATITUDE, Double.toString(latitude)); 28619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS longitude coordinate. This will be stored in JPEG EXIF 28659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * header. 28669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 28679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param longitude GPS longitude coordinate. 28689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsLongitude(double longitude) { 28709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_LONGITUDE, Double.toString(longitude)); 28719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS altitude. This will be stored in JPEG EXIF header. 28759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 28769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param altitude GPS altitude in meters. 28779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsAltitude(double altitude) { 28799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_ALTITUDE, Double.toString(altitude)); 28809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS timestamp. This will be stored in JPEG EXIF header. 28849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 28859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param timestamp GPS timestamp (UTC in seconds since January 1, 28869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 1970). 28879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsTimestamp(long timestamp) { 28899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); 28909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 2893e208377fbab6b90f41e68699700942a81f4caaebRay Chen * Sets GPS processing method. It will store up to 32 characters 2894055c986ab841f8f758398841730f1e90313b132aRay Chen * in JPEG EXIF header. 2895055c986ab841f8f758398841730f1e90313b132aRay Chen * 2896055c986ab841f8f758398841730f1e90313b132aRay Chen * @param processing_method The processing method to get this location. 2897055c986ab841f8f758398841730f1e90313b132aRay Chen */ 2898055c986ab841f8f758398841730f1e90313b132aRay Chen public void setGpsProcessingMethod(String processing_method) { 2899055c986ab841f8f758398841730f1e90313b132aRay Chen set(KEY_GPS_PROCESSING_METHOD, processing_method); 2900055c986ab841f8f758398841730f1e90313b132aRay Chen } 2901055c986ab841f8f758398841730f1e90313b132aRay Chen 2902055c986ab841f8f758398841730f1e90313b132aRay Chen /** 29039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Removes GPS latitude, longitude, altitude, and timestamp from the 29049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * parameters. 29059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void removeGpsData() { 29079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_LATITUDE); 29089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_LONGITUDE); 29099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_ALTITUDE); 29109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_TIMESTAMP); 2911055c986ab841f8f758398841730f1e90313b132aRay Chen remove(KEY_GPS_PROCESSING_METHOD); 29129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current white balance setting. 29169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29173f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current white balance. null if white balance setting is not 29183f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 29193f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_AUTO 29203f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_INCANDESCENT 29213f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_FLUORESCENT 29223f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_WARM_FLUORESCENT 29233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_DAYLIGHT 29243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT 29253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_TWILIGHT 29263f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_SHADE 29273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * 29289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getWhiteBalance() { 29309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_WHITE_BALANCE); 29319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 293416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * Sets the white balance. Changing the setting will release the 2935b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li * auto-white balance lock. It is recommended not to change white 2936b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li * balance and AWB lock at the same time. 29379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29383f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value new white balance. 29393f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getWhiteBalance() 2940037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 29419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setWhiteBalance(String value) { 2943b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li String oldValue = get(KEY_WHITE_BALANCE); 2944b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (same(value, oldValue)) return; 29459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_WHITE_BALANCE, value); 294616b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); 29479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported white balance. 29519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported white balance. null if white balance 29533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * setting is not supported. 29543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getWhiteBalance() 29559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedWhiteBalance() { 29579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); 29589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 29599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current color effect setting. 29639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current color effect. null if color effect 29659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 29663f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_NONE 29673f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_MONO 29683f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_NEGATIVE 29693f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_SOLARIZE 29703f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_SEPIA 29713f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_POSTERIZE 29723f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_WHITEBOARD 29733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_BLACKBOARD 29743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_AQUA 29759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getColorEffect() { 29779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_EFFECT); 29789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the current color effect setting. 29829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29833f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value new color effect. 29843f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getColorEffect() 29859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setColorEffect(String value) { 29879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_EFFECT, value); 29889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported color effects. 29929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29933f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported color effects. null if color effect 29949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 29953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getColorEffect() 29969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedColorEffects() { 29989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); 29999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 30009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current antibanding setting. 30059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current antibanding. null if antibanding setting is not 30073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 30083f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_AUTO 30093f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_50HZ 30103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_60HZ 30113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_OFF 30129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getAntibanding() { 30149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_ANTIBANDING); 30159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the antibanding. 30199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30203f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param antibanding new antibanding value. 30213f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getAntibanding() 30229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setAntibanding(String antibanding) { 30249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_ANTIBANDING, antibanding); 30259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported antibanding values. 30299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30303f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported antibanding values. null if antibanding 30313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * setting is not supported. 30323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getAntibanding() 30339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedAntibanding() { 30359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); 30369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 30379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current scene mode setting. 30419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return one of SCENE_MODE_XXX string constant. null if scene mode 30439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 30443f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_AUTO 30453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_ACTION 30463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_PORTRAIT 30473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_LANDSCAPE 30483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_NIGHT 30493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_NIGHT_PORTRAIT 30503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_THEATRE 30513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_BEACH 30523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SNOW 30533f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SUNSET 30543f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_STEADYPHOTO 30553f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_FIREWORKS 30563f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SPORTS 30573f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_PARTY 30583f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_CANDLELIGHT 3059da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * @see #SCENE_MODE_BARCODE 30609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getSceneMode() { 30629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_SCENE_MODE); 30639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 3066c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * Sets the scene mode. Changing scene mode may override other 3067c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * parameters (such as flash mode, focus mode, white balance). For 3068c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * example, suppose originally flash mode is on and supported flash 3069c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * modes are on/off. In night scene mode, both flash mode and supported 3070c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * flash mode may be changed to off. After setting scene mode, 30712988ab7c322aad7508df930204886f334216b65cWu-cheng Li * applications should call getParameters to know if some parameters are 30722988ab7c322aad7508df930204886f334216b65cWu-cheng Li * changed. 30739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value scene mode. 30753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getSceneMode() 30769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setSceneMode(String value) { 30789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_SCENE_MODE, value); 30799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported scene modes. 30839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30843f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported scene modes. null if scene mode setting 30853f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * is not supported. 30863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getSceneMode() 30879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedSceneModes() { 30899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); 30909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 30919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current flash mode setting. 30959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current flash mode. null if flash mode setting is not 30973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 30983f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_OFF 30993f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_AUTO 31003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_ON 31013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_RED_EYE 31023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_TORCH 31039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getFlashMode() { 31059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_FLASH_MODE); 31069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the flash mode. 31109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value flash mode. 31123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFlashMode() 31139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setFlashMode(String value) { 31159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_FLASH_MODE, value); 31169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported flash modes. 31209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31213f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported flash modes. null if flash mode setting 31223f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * is not supported. 31233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFlashMode() 31249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedFlashModes() { 31269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); 31279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 31289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 313036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 313136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Gets the current focus mode setting. 313236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 3133699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * @return current focus mode. This method will always return a non-null 3134699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * value. Applications should call {@link 3135699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * #autoFocus(AutoFocusCallback)} to start the focus if focus 3136699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. 31373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_AUTO 31383f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_INFINITY 31393f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_MACRO 31403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_FIXED 3141f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * @see #FOCUS_MODE_EDOF 3142d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li * @see #FOCUS_MODE_CONTINUOUS_VIDEO 314336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 314436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public String getFocusMode() { 314536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li return get(KEY_FOCUS_MODE); 314636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 314736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 314836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 314936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Sets the focus mode. 315036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 31513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value focus mode. 31523f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFocusMode() 315336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 315436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public void setFocusMode(String value) { 315536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li set(KEY_FOCUS_MODE, value); 315636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 315736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 315836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 315936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Gets the supported focus modes. 316036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 31613f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported focus modes. This method will always 31623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 31633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFocusMode() 316436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 316536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public List<String> getSupportedFocusModes() { 316636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); 316736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li return split(str); 316836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 316936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 317036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 31716c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the focal length (in millimeter) of the camera. 31726c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 31736c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return the focal length. This method will always return a valid 31746c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * value. 31756c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 31766c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getFocalLength() { 31776c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_FOCAL_LENGTH)); 31786c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 31796c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 31806c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 31816c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the horizontal angle of view in degrees. 31826c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 31836c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return horizontal angle of view. This method will always return a 31846c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * valid value. 31856c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 31866c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getHorizontalViewAngle() { 31876c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); 31886c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 31896c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 31906c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 31916c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the vertical angle of view in degrees. 31926c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 31936c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return vertical angle of view. This method will always return a 31946c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * valid value. 31956c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 31966c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getVerticalViewAngle() { 31976c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); 31986c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 31996c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 32006c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 320124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the current exposure compensation index. 3202ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 320324b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return current exposure compensation index. The range is {@link 320424b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMinExposureCompensation} to {@link 320524b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMaxExposureCompensation}. 0 means exposure is not 320624b326a8978bf78e3e560723dde221792784325bWu-cheng Li * adjusted. 3207ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 3208ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li public int getExposureCompensation() { 320924b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_EXPOSURE_COMPENSATION, 0); 3210ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3211ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3212ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 321324b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Sets the exposure compensation index. 3214ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 32150402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li * @param value exposure compensation index. The valid value range is 32160402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li * from {@link #getMinExposureCompensation} (inclusive) to {@link 321724b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMaxExposureCompensation} (inclusive). 0 means exposure is 321824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * not adjusted. Application should call 321924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * getMinExposureCompensation and getMaxExposureCompensation to 322024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * know if exposure compensation is supported. 3221ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 3222ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li public void setExposureCompensation(int value) { 3223ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li set(KEY_EXPOSURE_COMPENSATION, value); 3224ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3225ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3226ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 322724b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the maximum exposure compensation index. 3228ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 322924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return maximum exposure compensation index (>=0). If both this 323024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * method and {@link #getMinExposureCompensation} return 0, 323124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation is not supported. 323224b326a8978bf78e3e560723dde221792784325bWu-cheng Li */ 323324b326a8978bf78e3e560723dde221792784325bWu-cheng Li public int getMaxExposureCompensation() { 323424b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); 323524b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 323624b326a8978bf78e3e560723dde221792784325bWu-cheng Li 323724b326a8978bf78e3e560723dde221792784325bWu-cheng Li /** 323824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the minimum exposure compensation index. 323924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * 324024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return minimum exposure compensation index (<=0). If both this 324124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * method and {@link #getMaxExposureCompensation} return 0, 324224b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation is not supported. 3243ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 324424b326a8978bf78e3e560723dde221792784325bWu-cheng Li public int getMinExposureCompensation() { 324524b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); 324624b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 324724b326a8978bf78e3e560723dde221792784325bWu-cheng Li 324824b326a8978bf78e3e560723dde221792784325bWu-cheng Li /** 324924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the exposure compensation step. 325024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * 325124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return exposure compensation step. Applications can get EV by 325224b326a8978bf78e3e560723dde221792784325bWu-cheng Li * multiplying the exposure compensation index and step. Ex: if 325324b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation index is -6 and step is 0.333333333, EV 325424b326a8978bf78e3e560723dde221792784325bWu-cheng Li * is -2. 325524b326a8978bf78e3e560723dde221792784325bWu-cheng Li */ 325624b326a8978bf78e3e560723dde221792784325bWu-cheng Li public float getExposureCompensationStep() { 325724b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); 3258ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3259ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3260ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 3261d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Sets the auto-exposure lock state. Applications should check 3262d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #isAutoExposureLockSupported} before using this method.</p> 32633773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 3264d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If set to true, the camera auto-exposure routine will immediately 3265d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * pause until the lock is set to false. Exposure compensation settings 3266d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * changes will still take effect while auto-exposure is locked.</p> 3267d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3268d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If auto-exposure is already locked, setting this to true again has 3269d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * no effect (the driver will not recalculate exposure values).</p> 3270d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3271d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Stopping preview with {@link #stopPreview()}, or triggering still 3272d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * image capture with {@link #takePicture(Camera.ShutterCallback, 3273b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}, will not change the 3274b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * lock.</p> 3275d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3276b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * <p>Exposure compensation, auto-exposure lock, and auto-white balance 3277b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * lock can be used to capture an exposure-bracketed burst of images, 3278b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * for example.</p> 3279d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3280d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Auto-exposure state, including the lock state, will not be 32813773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * maintained after camera {@link #release()} is called. Locking 32823773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * auto-exposure after {@link #open()} but before the first call to 32833773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #startPreview()} will not allow the auto-exposure routine to 3284d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * run at all, and may result in severely over- or under-exposed 3285d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * images.</p> 32863773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 32873773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @param toggle new state of the auto-exposure lock. True means that 32883773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * auto-exposure is locked, false means that the auto-exposure 32893773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * routine is free to run normally. 32903773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 3291d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #getAutoExposureLock() 32923773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 32933773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public void setAutoExposureLock(boolean toggle) { 32943773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); 32953773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 32963773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 32973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 32983773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * Gets the state of the auto-exposure lock. Applications should check 32993773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #isAutoExposureLockSupported} before using this method. See 33003773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #setAutoExposureLock} for details about the lock. 33013773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @return State of the auto-exposure lock. Returns true if 3303b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * auto-exposure is currently locked, and false otherwise. 33043773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33053773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @see #setAutoExposureLock(boolean) 33063773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33073773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 33083773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public boolean getAutoExposureLock() { 33093773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala String str = get(KEY_AUTO_EXPOSURE_LOCK); 33103773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala return TRUE.equals(str); 33113773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 33123773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 33133773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 33143773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * Returns true if auto-exposure locking is supported. Applications 33153773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * should call this before trying to lock auto-exposure. See 33163773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #setAutoExposureLock} for details about the lock. 33173773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33183773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @return true if auto-exposure lock is supported. 33193773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @see #setAutoExposureLock(boolean) 33203773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33213773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 33223773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public boolean isAutoExposureLockSupported() { 33233773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); 33243773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala return TRUE.equals(str); 33253773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 33263773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 33273773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 3328d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Sets the auto-white balance lock state. Applications should check 3329d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #isAutoWhiteBalanceLockSupported} before using this 3330d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * method.</p> 3331d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3332d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If set to true, the camera auto-white balance routine will 3333d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * immediately pause until the lock is set to false.</p> 3334d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3335d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If auto-white balance is already locked, setting this to true 3336d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * again has no effect (the driver will not recalculate white balance 3337d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * values).</p> 3338d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3339d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Stopping preview with {@link #stopPreview()}, or triggering still 3340d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * image capture with {@link #takePicture(Camera.ShutterCallback, 3341b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}, will not change the 3342b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * the lock.</p> 3343d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 334416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * <p> Changing the white balance mode with {@link #setWhiteBalance} 334516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * will release the auto-white balance lock if it is set.</p> 334616b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * 3347b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * <p>Exposure compensation, AE lock, and AWB lock can be used to 3348b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * capture an exposure-bracketed burst of images, for example. 3349b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Auto-white balance state, including the lock state, will not be 3350b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * maintained after camera {@link #release()} is called. Locking 3351b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * auto-white balance after {@link #open()} but before the first call to 3352b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * {@link #startPreview()} will not allow the auto-white balance routine 3353b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * to run at all, and may result in severely incorrect color in captured 3354b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * images.</p> 3355d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3356d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @param toggle new state of the auto-white balance lock. True means 3357d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * that auto-white balance is locked, false means that the 3358d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * auto-white balance routine is free to run normally. 3359d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3360d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #getAutoWhiteBalanceLock() 336116b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * @see #setWhiteBalance(String) 3362d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3363d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public void setAutoWhiteBalanceLock(boolean toggle) { 3364d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); 3365d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3366d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3367d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 3368d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * Gets the state of the auto-white balance lock. Applications should 3369d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * check {@link #isAutoWhiteBalanceLockSupported} before using this 3370d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * method. See {@link #setAutoWhiteBalanceLock} for details about the 3371d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * lock. 3372d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3373d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @return State of the auto-white balance lock. Returns true if 3374d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * auto-white balance is currently locked, and false 3375b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * otherwise. 3376d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3377d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 3378d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3379d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3380d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public boolean getAutoWhiteBalanceLock() { 3381d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala String str = get(KEY_AUTO_WHITEBALANCE_LOCK); 3382d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala return TRUE.equals(str); 3383d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3384d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3385d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 3386d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * Returns true if auto-white balance locking is supported. Applications 3387d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * should call this before trying to lock auto-white balance. See 3388d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #setAutoWhiteBalanceLock} for details about the lock. 3389d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3390d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @return true if auto-white balance lock is supported. 3391d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 3392d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3393d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3394d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public boolean isAutoWhiteBalanceLockSupported() { 3395d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); 3396d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala return TRUE.equals(str); 3397d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3398d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3399d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 340036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Gets current zoom value. This also works when smooth zoom is in 34018cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * progress. Applications should check {@link #isZoomSupported} before 34028cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * using this method. 340336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 340436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return the current zoom value. The range is 0 to {@link 34058cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * #getMaxZoom}. 0 means the camera is not zoomed. 340636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 340736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public int getZoom() { 34088cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return getInt(KEY_ZOOM, 0); 340936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 341036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 341136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 34128cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Sets current zoom value. If the camera is zoomed (value > 0), the 34138cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * actual picture size may be smaller than picture size setting. 34148cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Applications can check the actual picture size after picture is 34158cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * returned from {@link PictureCallback}. The preview size remains the 34168cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * same in zoom. Applications should check {@link #isZoomSupported} 34178cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * before using this method. 341836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 341936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}. 342036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 342136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public void setZoom(int value) { 34228cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li set(KEY_ZOOM, value); 342336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 342436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 342536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 342636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Returns true if zoom is supported. Applications should call this 342736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * before using other zoom methods. 342836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 342936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return true if zoom is supported. 343036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 343136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public boolean isZoomSupported() { 34328cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li String str = get(KEY_ZOOM_SUPPORTED); 34338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return TRUE.equals(str); 343436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 343536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 343636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 343736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Gets the maximum zoom value allowed for snapshot. This is the maximum 343836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * value that applications can set to {@link #setZoom(int)}. 34398cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Applications should call {@link #isZoomSupported} before using this 34408cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * method. This value may change in different preview size. Applications 34418cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * should call this again after setting preview size. 344236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 344336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return the maximum zoom value supported by the camera. 344436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 344536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public int getMaxZoom() { 34468cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return getInt(KEY_MAX_ZOOM, 0); 344736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 344836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 344936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 34508cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Gets the zoom ratios of all zoom values. Applications should check 34518cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * {@link #isZoomSupported} before using this method. 345236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 34538cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is 34548cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * returned as 320. The number of elements is {@link 34558cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * #getMaxZoom} + 1. The list is sorted from small to large. The 34568cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * first element is always 100. The last element is the zoom 34578cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * ratio of the maximum zoom value. 345836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 34598cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li public List<Integer> getZoomRatios() { 34608cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return splitInt(get(KEY_ZOOM_RATIOS)); 346136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 346236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 346336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 346436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Returns true if smooth zoom is supported. Applications should call 346536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * this before using other smooth zoom methods. 346636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 346736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return true if smooth zoom is supported. 346836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 346936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public boolean isSmoothZoomSupported() { 34708cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); 34718cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return TRUE.equals(str); 347236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 347336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 3474e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li /** 347532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the distances from the camera to where an object appears to be 3476e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * in focus. The object is sharpest at the optimal focus distance. The 347732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * depth of field is the far focus distance minus near focus distance.</p> 3478e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 347932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus distances may change after calling {@link 3480e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link 3481e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * #startPreview()}. Applications can call {@link #getParameters()} 3482e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * and this method anytime to get the latest focus distances. If the 3483d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change 348432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * from time to time.</p> 3485699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * 348632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>This method is intended to estimate the distance between the camera 3487699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * and the subject. After autofocus, the subject distance may be within 3488699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * near and far focus distance. However, the precision depends on the 3489699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * camera hardware, autofocus algorithm, the focus area, and the scene. 349032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * The error can be large and it should be only used as a reference.</p> 3491e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 349232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Far focus distance >= optimal focus distance >= near focus distance. 3493185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * If the focus distance is infinity, the value will be 349432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * {@code Float.POSITIVE_INFINITY}.</p> 3495e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 3496e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * @param output focus distances in meters. output must be a float 3497e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * array with three elements. Near focus distance, optimal focus 3498e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * distance, and far focus distance will be filled in the array. 3499185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_NEAR_INDEX 3500185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_OPTIMAL_INDEX 3501185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_FAR_INDEX 3502e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li */ 3503e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li public void getFocusDistances(float[] output) { 3504e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li if (output == null || output.length != 3) { 3505e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li throw new IllegalArgumentException( 3506f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa "output must be a float array with three elements."); 3507e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3508454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitFloat(get(KEY_FOCUS_DISTANCES), output); 3509e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3510e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 351130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 351230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Gets the maximum number of focus areas supported. This is the maximum 35137b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * length of the list in {@link #setFocusAreas(List)} and 35147b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * {@link #getFocusAreas()}. 351530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 351630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @return the maximum number of focus areas supported by the camera. 351730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @see #getFocusAreas() 351830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 351930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public int getMaxNumFocusAreas() { 352030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); 352130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 352230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 352330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 352432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the current focus areas. Camera driver uses the areas to decide 352532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * focus.</p> 352630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 352732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Before using this API or {@link #setFocusAreas(List)}, apps should 35287b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * call {@link #getMaxNumFocusAreas()} to know the maximum number of 352932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * focus areas first. If the value is 0, focus area is not supported.</p> 353030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 353132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Each focus area is a rectangle with specified weight. The direction 353230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * is relative to the sensor orientation, that is, what the sensor sees. 353330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * The direction is not affected by the rotation or mirroring of 353430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle 353530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * range from -1000 to 1000. (-1000, -1000) is the upper left point. 3536bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * (1000, 1000) is the lower right point. The width and height of focus 353732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * areas cannot be 0 or negative.</p> 353830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 353932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The weight must range from 1 to 1000. The weight should be 35404e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * interpreted as a per-pixel weight - all pixels in the area have the 35414e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * specified weight. This means a small area with the same weight as a 35424e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * larger area will have less influence on the focusing than the larger 35434e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * area. Focus areas can partially overlap and the driver will add the 354432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * weights in the overlap region.</p> 354530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 354632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>A special case of a {@code null} focus area list means the driver is 354732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * free to select focus targets as it wants. For example, the driver may 354832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * use more signals to select focus areas and change them 354932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * dynamically. Apps can set the focus area list to {@code null} if they 355032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * want the driver to completely control focusing.</p> 355130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 355232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus areas are relative to the current field of view 355330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) 355430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * represents the top of the currently visible camera frame. The focus 355530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * area cannot be set to be outside the current field of view, even 355632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * when using zoom.</p> 355730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 355832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus area only has effect if the current focus mode is 355953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, 356053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or 356153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> 356230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 356330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @return a list of current focus areas 356430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 356530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public List<Area> getFocusAreas() { 3566f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li return splitArea(get(KEY_FOCUS_AREAS)); 356730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 356830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 356930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 357030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Sets focus areas. See {@link #getFocusAreas()} for documentation. 357130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 35727b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * @param focusAreas the focus areas 357330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @see #getFocusAreas() 357430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 3575e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public void setFocusAreas(List<Area> focusAreas) { 3576e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li set(KEY_FOCUS_AREAS, focusAreas); 3577e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3578e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3579e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 3580e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * Gets the maximum number of metering areas supported. This is the 35817b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * maximum length of the list in {@link #setMeteringAreas(List)} and 35827b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * {@link #getMeteringAreas()}. 3583e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 3584e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @return the maximum number of metering areas supported by the camera. 3585e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @see #getMeteringAreas() 3586e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3587e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public int getMaxNumMeteringAreas() { 3588e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li return getInt(KEY_MAX_NUM_METERING_AREAS, 0); 3589e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3590e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3591e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 359232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the current metering areas. Camera driver uses these areas to 359332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * decide exposure.</p> 3594e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 359532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should 35967b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * call {@link #getMaxNumMeteringAreas()} to know the maximum number of 35977b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * metering areas first. If the value is 0, metering area is not 359832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * supported.</p> 3599e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 360032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Each metering area is a rectangle with specified weight. The 3601e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * direction is relative to the sensor orientation, that is, what the 3602e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * sensor sees. The direction is not affected by the rotation or 3603e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the 3604e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left 3605bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * point. (1000, 1000) is the lower right point. The width and height of 360632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * metering areas cannot be 0 or negative.</p> 3607e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 360832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The weight must range from 1 to 1000, and represents a weight for 36094e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * every pixel in the area. This means that a large metering area with 36104e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * the same weight as a smaller area will have more effect in the 36114e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * metering result. Metering areas can partially overlap and the driver 361232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * will add the weights in the overlap region.</p> 3613e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 361432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>A special case of a {@code null} metering area list means the driver 361532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * is free to meter as it chooses. For example, the driver may use more 361632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * signals to select metering areas and change them dynamically. Apps 361732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * can set the metering area list to {@code null} if they want the 361832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * driver to completely control metering.</p> 3619e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 362032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Metering areas are relative to the current field of view 3621e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) 3622e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * represents the top of the currently visible camera frame. The 3623e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * metering area cannot be set to be outside the current field of view, 362432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * even when using zoom.</p> 3625e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 362632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>No matter what metering areas are, the final exposure are compensated 362732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * by {@link #setExposureCompensation(int)}.</p> 3628e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 3629e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @return a list of current metering areas 3630e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3631e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public List<Area> getMeteringAreas() { 3632d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li return splitArea(get(KEY_METERING_AREAS)); 3633e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3634e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3635e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 3636e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * Sets metering areas. See {@link #getMeteringAreas()} for 3637e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * documentation. 3638e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 36397b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * @param meteringAreas the metering areas 3640e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @see #getMeteringAreas() 3641e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3642e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public void setMeteringAreas(List<Area> meteringAreas) { 3643e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li set(KEY_METERING_AREAS, meteringAreas); 364430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 364530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 36464c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 36474c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Gets the maximum number of detected faces supported. This is the 36484c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * maximum length of the list returned from {@link FaceDetectionListener}. 36494c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * If the return value is 0, face detection of the specified type is not 36504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * supported. 36514c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 36524c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @return the maximum number of detected face supported by the camera. 3653464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see #startFaceDetection() 36544c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 3655c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li public int getMaxNumDetectedFaces() { 3656c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); 36574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 36584c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 365925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li /** 36609c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * Sets recording mode hint. This tells the camera that the intent of 36619c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * the application is to record videos {@link 36629c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * android.media.MediaRecorder#start()}, not to take still pictures 36639c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, 36649c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can 36659c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * allow MediaRecorder.start() to start faster or with fewer glitches on 36669c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * output. This should be called before starting preview for the best 36679c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * result, but can be changed while the preview is active. The default 36689c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * value is false. 36699c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * 36709c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * The app can still call takePicture() when the hint is true or call 36719c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * MediaRecorder.start() when the hint is false. But the performance may 36729c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * be worse. 36739c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * 36749c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * @param hint true if the apps intend to record videos using 367525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li * {@link android.media.MediaRecorder}. 367625d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li */ 367725d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li public void setRecordingHint(boolean hint) { 367825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); 367925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li } 368025d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li 368198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li /** 36821cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Returns true if video snapshot is supported. That is, applications 368398bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * can call {@link #takePicture(Camera.ShutterCallback, 36841cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * Camera.PictureCallback, Camera.PictureCallback, 36851cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * Camera.PictureCallback)} during recording. Applications do not need 36861cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * to call {@link #startPreview()} after taking a picture. The preview 36871cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * will be still active. Other than that, taking a picture during 36881cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * recording is identical to taking a picture normally. All settings and 36891cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * methods related to takePicture work identically. Ex: 36901cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()}, 36911cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The 36921cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and 36931cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #FLASH_MODE_ON} also still work, but the video will record the 36941cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * flash.</p> 36951cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * 36961cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Applications can set shutter callback as null to avoid the shutter 369798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * sound. It is also recommended to set raw picture and post view 36981cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * callbacks to null to avoid the interrupt of preview display.</p> 369998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * 37001cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Field-of-view of the recorded video may be different from that of the 37011cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * captured pictures. The maximum size of a video snapshot may be 37021cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * smaller than that for regular still captures. If the current picture 37031cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * size is set higher than can be supported by video snapshot, the 37041cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * picture will be captured at the maximum supported size instead.</p> 370598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * 370698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * @return true if video snapshot is supported. 370798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li */ 370898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li public boolean isVideoSnapshotSupported() { 370998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); 371098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li return TRUE.equals(str); 371198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li } 371298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li 3713037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3714037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Enables and disables video stabilization. Use 3715037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #isVideoStabilizationSupported} to determine if calling this 3716037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * method is valid.</p> 3717037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3718037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Video stabilization reduces the shaking due to the motion of the 3719037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * camera in both the preview stream and in recorded videos, including 3720037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * data received from the preview callback. It does not reduce motion 3721037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * blur in images captured with 3722037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link Camera#takePicture takePicture}.</p> 3723037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3724037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Video stabilization can be enabled and disabled while preview or 3725037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * recording is active, but toggling it may cause a jump in the video 3726037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * stream that may be undesirable in a recorded video.</p> 3727037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3728037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @param toggle Set to true to enable video stabilization, and false to 3729037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * disable video stabilization. 3730037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #isVideoStabilizationSupported() 3731037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #getVideoStabilization() 3732037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3733037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public void setVideoStabilization(boolean toggle) { 3734037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); 3735037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3736037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 3737037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3738037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * Get the current state of video stabilization. See 3739037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #setVideoStabilization} for details of video stabilization. 3740037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3741037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @return true if video stabilization is enabled 3742037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #isVideoStabilizationSupported() 3743037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setVideoStabilization(boolean) 3744037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3745037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public boolean getVideoStabilization() { 3746037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala String str = get(KEY_VIDEO_STABILIZATION); 3747037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala return TRUE.equals(str); 3748037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3749037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 3750037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3751037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * Returns true if video stabilization is supported. See 3752037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #setVideoStabilization} for details of video stabilization. 3753037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3754037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @return true if video stabilization is supported 3755037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setVideoStabilization(boolean) 3756037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #getVideoStabilization() 3757037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3758037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public boolean isVideoStabilizationSupported() { 3759037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); 3760037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala return TRUE.equals(str); 3761037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3762037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 37639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of String. 37649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 37659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<String> split(String str) { 37669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 37679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 37680a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 37690a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 37709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<String> substrings = new ArrayList<String>(); 37710a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 37720a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen substrings.add(s); 37739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 37749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return substrings; 37759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 37769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 37779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of Integer. 37789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 37799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<Integer> splitInt(String str) { 37809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 37819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 37820a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 37830a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 37849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<Integer> substrings = new ArrayList<Integer>(); 37850a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 37860a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen substrings.add(Integer.parseInt(s)); 37879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 37889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (substrings.size() == 0) return null; 37899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return substrings; 37909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 37919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 3792454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private void splitInt(String str, int[] output) { 3793454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null) return; 3794454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 37950a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 37960a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 3797454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int index = 0; 37980a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 37990a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen output[index++] = Integer.parseInt(s); 3800454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3801454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3802454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3803e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li // Splits a comma delimited string to an ArrayList of Float. 3804454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private void splitFloat(String str, float[] output) { 3805454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null) return; 3806e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 38070a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38080a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 3809454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int index = 0; 38100a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38110a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen output[index++] = Float.parseFloat(s); 3812e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3813e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3814e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 381524b326a8978bf78e3e560723dde221792784325bWu-cheng Li // Returns the value of a float parameter. 381624b326a8978bf78e3e560723dde221792784325bWu-cheng Li private float getFloat(String key, float defaultValue) { 381724b326a8978bf78e3e560723dde221792784325bWu-cheng Li try { 381824b326a8978bf78e3e560723dde221792784325bWu-cheng Li return Float.parseFloat(mMap.get(key)); 381924b326a8978bf78e3e560723dde221792784325bWu-cheng Li } catch (NumberFormatException ex) { 382024b326a8978bf78e3e560723dde221792784325bWu-cheng Li return defaultValue; 382124b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 382224b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 382324b326a8978bf78e3e560723dde221792784325bWu-cheng Li 382424b326a8978bf78e3e560723dde221792784325bWu-cheng Li // Returns the value of a integer parameter. 382524b326a8978bf78e3e560723dde221792784325bWu-cheng Li private int getInt(String key, int defaultValue) { 382624b326a8978bf78e3e560723dde221792784325bWu-cheng Li try { 382724b326a8978bf78e3e560723dde221792784325bWu-cheng Li return Integer.parseInt(mMap.get(key)); 382824b326a8978bf78e3e560723dde221792784325bWu-cheng Li } catch (NumberFormatException ex) { 382924b326a8978bf78e3e560723dde221792784325bWu-cheng Li return defaultValue; 383024b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 383124b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 383224b326a8978bf78e3e560723dde221792784325bWu-cheng Li 38339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of Size. 38349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 38359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<Size> splitSize(String str) { 38369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38380a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38390a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 38409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<Size> sizeList = new ArrayList<Size>(); 38410a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38420a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen Size size = strToSize(s); 38439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (size != null) sizeList.add(size); 38449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (sizeList.size() == 0) return null; 38469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return sizeList; 38479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Parses a string (ex: "480x320") to Size object. 38509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null. 38519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private Size strToSize(String str) { 38529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li int pos = str.indexOf('x'); 38559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (pos != -1) { 38569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String width = str.substring(0, pos); 38579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String height = str.substring(pos + 1); 38589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return new Size(Integer.parseInt(width), 38599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li Integer.parseInt(height)); 38609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li Log.e(TAG, "Invalid size parameter string=" + str); 38629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return null; 38639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 3864454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3865454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // Splits a comma delimited string to an ArrayList of int array. 3866454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // Example string: "(10000,26623),(10000,30000)". Return null if the 3867454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // passing string is null or the size is 0. 3868454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private ArrayList<int[]> splitRange(String str) { 3869454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null || str.charAt(0) != '(' 3870454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li || str.charAt(str.length() - 1) != ')') { 3871454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li Log.e(TAG, "Invalid range list string=" + str); 3872454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return null; 3873454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3874454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3875454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li ArrayList<int[]> rangeList = new ArrayList<int[]>(); 3876454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int endIndex, fromIndex = 1; 3877454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li do { 3878454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int[] range = new int[2]; 3879454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li endIndex = str.indexOf("),(", fromIndex); 3880454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (endIndex == -1) endIndex = str.length() - 1; 3881454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitInt(str.substring(fromIndex, endIndex), range); 3882454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li rangeList.add(range); 3883454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li fromIndex = endIndex + 3; 3884454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } while (endIndex != str.length() - 1); 3885454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3886454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (rangeList.size() == 0) return null; 3887454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return rangeList; 3888454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 388930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 389030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li // Splits a comma delimited string to an ArrayList of Area objects. 389130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if 3892f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li // the passing string is null or the size is 0 or (0,0,0,0,0). 389330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li private ArrayList<Area> splitArea(String str) { 389430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (str == null || str.charAt(0) != '(' 389530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li || str.charAt(str.length() - 1) != ')') { 389630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li Log.e(TAG, "Invalid area string=" + str); 389730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return null; 389830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 389930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 390030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li ArrayList<Area> result = new ArrayList<Area>(); 390130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li int endIndex, fromIndex = 1; 390230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li int[] array = new int[5]; 390330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li do { 390430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li endIndex = str.indexOf("),(", fromIndex); 390530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (endIndex == -1) endIndex = str.length() - 1; 390630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li splitInt(str.substring(fromIndex, endIndex), array); 390730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li Rect rect = new Rect(array[0], array[1], array[2], array[3]); 390830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li result.add(new Area(rect, array[4])); 390930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li fromIndex = endIndex + 3; 391030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } while (endIndex != str.length() - 1); 391130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 391230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (result.size() == 0) return null; 3913f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li 3914f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (result.size() == 1) { 3915bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li Area area = result.get(0); 3916f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Rect rect = area.rect; 3917f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (rect.left == 0 && rect.top == 0 && rect.right == 0 3918f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li && rect.bottom == 0 && area.weight == 0) { 3919f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li return null; 3920f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 3921f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 3922f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li 392330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return result; 392430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 3925b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li 3926b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li private boolean same(String s1, String s2) { 3927b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (s1 == null && s2 == null) return true; 3928b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (s1 != null && s1.equals(s2)) return true; 3929b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li return false; 3930b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li } 39319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 39329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 3933