Camera.java revision feb50af361e4305a25758966b6b5df2738c00259
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 172feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk private static final int NO_ERROR = 0; 173feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk private static final int EACCESS = -13; 174feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk private static final int ENODEV = -19; 175feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk 1769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * Broadcast Action: A new picture is taken by the camera, and the entry of 17810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * the picture has been added to the media store. 17910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * {@link android.content.Intent#getData} is URI of the picture. 18010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li */ 18110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 18210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"; 18310e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li 18410e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li /** 18510e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * Broadcast Action: A new video is recorded by the camera, and the entry 18610e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * of the video has been added to the media store. 18710e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li * {@link android.content.Intent#getData} is URI of the video. 18810e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li */ 18910e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 19010e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"; 19110e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li 19210e09c69d659bf54d6efbe1a3660add7f8a39d6eWu-cheng Li /** 1934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Hardware face detection. It does not use much CPU. 1944c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 195c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li private static final int CAMERA_FACE_DETECTION_HW = 0; 1964c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 1974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 198c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Software face detection. It uses some CPU. 1994c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 200c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li private static final int CAMERA_FACE_DETECTION_SW = 1; 2014c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 2024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 203341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * Returns the number of physical cameras available on this device. 204e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang */ 205e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang public native static int getNumberOfCameras(); 206e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang 207e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang /** 208341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * Returns the information about a particular camera. 209b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1. 210b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang */ 2114f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) { 2124f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala _getCameraInfo(cameraId, cameraInfo); 2134f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); 2144f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala IAudioService audioService = IAudioService.Stub.asInterface(b); 2154f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala try { 2164f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala if (audioService.isCameraSoundForced()) { 2174f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala // Only set this when sound is forced; otherwise let native code 2184f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala // decide. 2194f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala cameraInfo.canDisableShutterSound = false; 2204f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 2214f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } catch (RemoteException e) { 2224f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala Log.e(TAG, "Audio service is unavailable for queries"); 2234f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 2244f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 2254f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo); 226b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang 227b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang /** 228b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * Information about a camera 229b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang */ 230b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang public static class CameraInfo { 2317836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li /** 2327836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li * The facing of the camera is opposite to that of the screen. 2337836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li */ 234b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang public static final int CAMERA_FACING_BACK = 0; 2357836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li 2367836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li /** 2377836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li * The facing of the camera is the same as that of the screen. 2387836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li */ 239b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang public static final int CAMERA_FACING_FRONT = 1; 240b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang 241b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang /** 242464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * The direction that the camera faces. It should be 243b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. 244b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang */ 2457836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li public int facing; 246b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang 247b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang /** 24832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The orientation of the camera image. The value is the angle that the 249b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * camera image needs to be rotated clockwise so it shows correctly on 25032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the display in its natural orientation. It should be 0, 90, 180, or 270.</p> 251b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * 25232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>For example, suppose a device has a naturally tall screen. The 2532fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * back-facing camera sensor is mounted in landscape. You are looking at 2542fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * the screen. If the top side of the camera sensor is aligned with the 2552fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * right edge of the screen in natural orientation, the value should be 2562fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * 90. If the top side of a front-facing camera sensor is aligned with 25732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the right of the screen, the value should be 270.</p> 258b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * 259b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * @see #setDisplayOrientation(int) 26069ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * @see Parameters#setRotation(int) 26169ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * @see Parameters#setPreviewSize(int, int) 26269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * @see Parameters#setPictureSize(int, int) 26369ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * @see Parameters#setJpegThumbnailSize(int, int) 264b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang */ 2657836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li public int orientation; 266f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala 267f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala /** 268f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * <p>Whether the shutter sound can be disabled.</p> 269f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * 270f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * <p>On some devices, the camera shutter sound cannot be turned off 271f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * through {@link #enableShutterSound enableShutterSound}. This field 272f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * can be used to determine whether a call to disable the shutter sound 273f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * will succeed.</p> 274f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * 275f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * <p>If this field is set to true, then a call of 276f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * {@code enableShutterSound(false)} will be successful. If set to 277f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * false, then that call will fail, and the shutter sound will be played 278f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala * when {@link Camera#takePicture takePicture} is called.</p> 279f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala */ 280f7c6c5ad64c8e5d20e1806cc98b9919334c69614Eino-Ville Talvala public boolean canDisableShutterSound; 281b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang }; 282b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang 283b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang /** 284a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * Creates a new Camera object to access a particular hardware camera. If 285a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * the same camera is opened by other applications, this will throw a 286a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * RuntimeException. 287a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * 288bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>You must call {@link #release()} when you are done using the camera, 289bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * otherwise it will remain locked and be unavailable to other applications. 290bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 291341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * <p>Your application should only have one Camera object active at a time 292341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * for a particular hardware camera. 293bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 294bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>Callbacks from other methods are delivered to the event loop of the 295bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * thread which called open(). If this thread has no event loop, then 296bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * callbacks are delivered to the main application event loop. If there 297bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * is no main application event loop, callbacks are not delivered. 298bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 299bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p class="caution"><b>Caution:</b> On some devices, this method may 300bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * take a long time to complete. It is best to call this method from a 301bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * worker thread (possibly using {@link android.os.AsyncTask}) to avoid 302bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * blocking the main application UI thread. 303bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 304341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * @param cameraId the hardware camera to access, between 0 and 305a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li * {@link #getNumberOfCameras()}-1. 306bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @return a new Camera object, connected, locked and ready for use. 307a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * @throws RuntimeException if opening the camera fails (for example, if the 308a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * camera is in use by another process or device policy manager has 309a1c41e13b521cdd611a8fc46e43b5ae0a2c00238Wu-cheng Li * disabled the camera). 310facc8ce116bd92f7ba7e8ecb76cbda3953260ef9Wu-cheng Li * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) 311e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang */ 312e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang public static Camera open(int cameraId) { 3137bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li return new Camera(cameraId); 314e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang } 315e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang 316e25cc656392d8866e163f78b60c7791455d0fb44Chih-Chung Chang /** 317a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li * Creates a new Camera object to access the first back-facing camera on the 318a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li * device. If the device does not have a back-facing camera, this returns 319a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li * null. 3207836660f5eb45b7b7e1f5119face65c80e2ade17Wu-cheng Li * @see #open(int) 3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static Camera open() { 323a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li int numberOfCameras = getNumberOfCameras(); 324a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li CameraInfo cameraInfo = new CameraInfo(); 325a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li for (int i = 0; i < numberOfCameras; i++) { 326a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li getCameraInfo(i, cameraInfo); 327a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { 3287bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li return new Camera(i); 329a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li } 330a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li } 331a48b70fa8ff6363d1e5282be70f6be12bc0688dcWu-cheng Li return null; 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3347bc1b21a5217c3737ae82edd3ff2d901c69a51adWu-cheng Li Camera(int cameraId) { 335feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk int err = cameraInit(cameraId); 336feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk if (checkInitErrors(err)) { 337feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk switch(err) { 338feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk case EACCESS: 339feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk throw new RuntimeException("Fail to connect to camera service"); 340feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk case ENODEV: 341feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk throw new RuntimeException("Camera initialization failed"); 342feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk default: 343feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk // Should never hit this. 344feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk throw new RuntimeException("Unknown camera error"); 345feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk } 346feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk } 347feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk } 348feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk 349feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk /** 350feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk * @hide 351feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk */ 352feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk public int cameraInit(int cameraId) { 3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mShutterCallback = null; 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mRawImageCallback = null; 3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mJpegCallback = null; 3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPreviewCallback = null; 357e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks mPostviewCallback = null; 3587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = false; 3593f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li mZoomListener = null; 3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Looper looper; 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if ((looper = Looper.myLooper()) != null) { 3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if ((looper = Looper.getMainLooper()) != null) { 3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 3679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = null; 3689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 370788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala String packageName = ActivityThread.currentPackageName(); 371788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala 372feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk return native_setup(new WeakReference<Camera>(this), cameraId, packageName); 373feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk } 374feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk 375feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk /** 376feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk * @hide 377feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk */ 378feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk public static boolean checkInitErrors(int err) { 379feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk return err != NO_ERROR; 380feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk } 381feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk 382feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk /** 383feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk * @hide 384feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk */ 385feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk public static Camera openUninitialized() { 386feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk return new Camera(); 3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 3891c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li /** 3901c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li * An empty Camera for testing purpose. 3911c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li */ 3921c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li Camera() { 3931c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li } 3941c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li 3959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li protected void finalize() { 396e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala release(); 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 399feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk private native final int native_setup(Object camera_this, int cameraId, 400788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala String packageName); 401788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_release(); 4039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Disconnects and releases the Camera object resources. 407bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 408bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>You must call this as soon as you're done with the Camera object.</p> 4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public final void release() { 4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_release(); 4124c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li mFaceDetectionRunning = false; 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 416bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Unlocks the camera to allow another process to access it. 417bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Normally, the camera is locked to the process with an active Camera 418bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * object until {@link #release()} is called. To allow rapid handoff 419bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * between processes, you can call this method to release the camera 420bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * temporarily for another process to use; once the other process is done 421bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * you can call {@link #reconnect()} to reclaim the camera. 422bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 423bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This must be done before calling 42442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be 42542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * called after recording starts. 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 427bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>If you are not recording video, you probably do not need this method. 4289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 429bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @throws RuntimeException if the camera cannot be unlocked. 4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 431bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor public native final void unlock(); 4329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 434bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Re-locks the camera to prevent other processes from accessing it. 435bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera objects are locked by default unless {@link #unlock()} is 436bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * called. Normally {@link #reconnect()} is used instead. 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 43853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * <p>Since API level 14, camera is automatically locked for applications in 43942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link android.media.MediaRecorder#start()}. Applications can use the 44042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * camera (ex: zoom) after recording starts. There is no need to call this 44142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * after recording starts or stops. 44242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * 443bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>If you are not recording video, you probably do not need this method. 444bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 445bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @throws RuntimeException if the camera cannot be re-locked (for 446bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * example, if the camera is still in use by another process). 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 448ffe1cf251a4f8469695b8acfa37270684dc1b70cWu-cheng Li public native final void lock(); 4499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 451bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Reconnects to the camera service after another process used it. 452bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * After {@link #unlock()} is called, another process may use the 453bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * camera; when the process is done, you must reconnect to the camera, 454bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * which will re-acquire the lock and allow you to continue using the 455bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * camera. 4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 45753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * <p>Since API level 14, camera is automatically locked for applications in 45842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link android.media.MediaRecorder#start()}. Applications can use the 45942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * camera (ex: zoom) after recording starts. There is no need to call this 46042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * after recording starts or stops. 461bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 462bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>If you are not recording video, you probably do not need this method. 463bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 464bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @throws IOException if a connection cannot be re-established (for 465bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * example, if the camera is still in use by another process). 4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 467bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor public native final void reconnect() throws IOException; 4689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 470bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Sets the {@link Surface} 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 can be re-set 473fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * without harm. Setting a preview surface will un-set any preview surface 474fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * texture that was set via {@link #setPreviewTexture}. 4759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 476bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>The {@link SurfaceHolder} must already contain a surface when this 477bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * method is called. If you are using {@link android.view.SurfaceView}, 478bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * you will need to register a {@link SurfaceHolder.Callback} with 479bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for 480bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before 481bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * calling setPreviewDisplay() or starting preview. 482bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 483bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This method must be called before {@link #startPreview()}. The 484bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * one exception is that if the preview surface is not set (or set to null) 485bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * before startPreview() is called, then this method may be called once 486bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * with a non-null parameter to set the preview surface. (This allows 487bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * camera setup and surface creation to happen in parallel, saving time.) 488bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The preview surface may not otherwise change while preview is running. 4899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 490bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param holder containing the Surface on which to place the preview, 491bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or null to remove the preview surface 492bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @throws IOException if the method fails (for example, if the surface 493bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * is unavailable or unsuitable). 4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { 496b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li if (holder != null) { 497feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk setPreviewSurface(holder.getSurface()); 498b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li } else { 499feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk setPreviewSurface((Surface)null); 500b8a10fe45657f2dcc50cae8a06805f8438a6937eWu-cheng Li } 5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 503feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk /** 504feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk * @hide 505feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk */ 506feb50af361e4305a25758966b6b5df2738c00259Ruben Brunk public native final void setPreviewSurface(Surface surface) throws IOException; 5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 509fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * Sets the {@link SurfaceTexture} to be used for live preview. 510fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * Either a surface or surface texture is necessary for preview, and 511fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * preview is necessary to take pictures. The same surface texture can be 512fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * re-set without harm. Setting a preview surface texture will un-set any 513fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * preview surface that was set via {@link #setPreviewDisplay}. 514fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * 515fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * <p>This method must be called before {@link #startPreview()}. The 516fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * one exception is that if the preview surface texture is not set (or set 517fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * to null) before startPreview() is called, then this method may be called 518fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * once with a non-null parameter to set the preview surface. (This allows 519fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * camera setup and surface creation to happen in parallel, saving time.) 520fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * The preview surface texture may not otherwise change while preview is 521fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * running. 522fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * 52332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a 524e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala * SurfaceTexture set as the preview texture have an unspecified zero point, 525e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala * and cannot be directly compared between different cameras or different 526e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala * instances of the same camera, or across multiple runs of the same 527e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala * program. 528e309a0fd2e528039b3c1f1372a9a7095bcd852ccEino-Ville Talvala * 529108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>If you are using the preview data to create video or still images, 530108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * strongly consider using {@link android.media.MediaActionSound} to 531108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * properly indicate image capture or recording start/stop to the user.</p> 532108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * 533108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.media.MediaActionSound 534108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.graphics.SurfaceTexture 535108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.view.TextureView 536fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * @param surfaceTexture the {@link SurfaceTexture} to which the preview 537fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * images are to be sent or null to remove the current preview surface 538fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * texture 539fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * @throws IOException if the method fails (for example, if the surface 540fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis * texture is unavailable or unsuitable). 541fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis */ 542dbc289d6c27968bd05cc547ca73579347c3adc99Glenn Kasten public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException; 543fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis 544fd6f39e147dc077139a41b9c2a4039fbaa20224eJamie Gennis /** 545bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface used to deliver copies of preview frames as 546bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * they are displayed. 547bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 548bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setPreviewCallback(Camera.PreviewCallback) 549bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setOneShotPreviewCallback(Camera.PreviewCallback) 550bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) 551bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #startPreview() 5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface PreviewCallback 5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 556bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Called as preview frames are displayed. This callback is invoked 557341ff13689dfe822b598e626272ac2e80041b482Dan Egnor * on the event thread {@link #open(int)} was called from. 5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 559951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>If using the {@link android.graphics.ImageFormat#YV12} format, 560951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * refer to the equations in {@link Camera.Parameters#setPreviewFormat} 561951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * for the arrangement of the pixel data in the preview callback 562951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * buffers. 563951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 564bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param data the contents of the preview frame in the format defined 565a696f5d667227365da732481770767dcb330dd23Mathias Agopian * by {@link android.graphics.ImageFormat}, which can be queried 566df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. 567da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} 5689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * is never called, the default will be the YCbCr_420_SP 5699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * (NV21) format. 570bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param camera the Camera service object. 5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onPreviewFrame(byte[] data, Camera camera); 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 5749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 576bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Starts capturing and drawing preview frames to the screen. 577c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * Preview will not actually start until a surface is supplied 578c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * with {@link #setPreviewDisplay(SurfaceHolder)} or 579c5f94d8a4779050125145396ca83fbc862c7ed6bEino-Ville Talvala * {@link #setPreviewTexture(SurfaceTexture)}. 580bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 581bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)}, 582bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or 583bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were 584bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)} 585bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * will be called when preview data becomes available. 5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native final void startPreview(); 5889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 590bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Stops capturing and drawing preview frames to the surface, and 591bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * resets the camera for a future call to {@link #startPreview()}. 5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li public final void stopPreview() { 5944c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li _stopPreview(); 5954c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li mFaceDetectionRunning = false; 596664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang 597664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang mShutterCallback = null; 598664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang mRawImageCallback = null; 599664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang mPostviewCallback = null; 600664d72e6630522589cc013b25f5c9cdd5d949fa3Chih-yu Huang mJpegCallback = null; 601f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li synchronized (mAutoFocusCallbackLock) { 602f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li mAutoFocusCallback = null; 603f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li } 6049d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li mAutoFocusMoveCallback = null; 6054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 6064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 6074c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li private native final void _stopPreview(); 6089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return current preview state. 6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * FIXME: Unhide before release 6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @hide 6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native final boolean previewEnabled(); 6169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 618108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>Installs a callback to be invoked for every preview frame in addition 619bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * to displaying them on the screen. The callback will be repeatedly called 620bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * for as long as preview is active. This method can be called at any time, 621108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * even while preview is live. Any other preview callbacks are 622108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * overridden.</p> 623108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * 624108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>If you are using the preview data to create video or still images, 625108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * strongly consider using {@link android.media.MediaActionSound} to 626108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * properly indicate image capture or recording start/stop to the user.</p> 6279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 628bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param cb a callback object that receives a copy of each preview frame, 629bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or null to stop receiving callbacks. 630108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.media.MediaActionSound 6319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void setPreviewCallback(PreviewCallback cb) { 6339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPreviewCallback = cb; 6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOneShot = false; 63594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mWithBuffer = false; 6367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (cb != null) { 6377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = false; 6387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 639a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // Always use one-shot mode. We fake camera preview mode by 640a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // doing one-shot preview continuously. 64194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp setHasPreviewCallback(cb != null, false); 6429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 645108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>Installs a callback to be invoked for the next preview frame in 646108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * addition to displaying it on the screen. After one invocation, the 647108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * callback is cleared. This method can be called any time, even when 648108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * preview is live. Any other preview callbacks are overridden.</p> 649108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * 650108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>If you are using the preview data to create video or still images, 651108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * strongly consider using {@link android.media.MediaActionSound} to 652108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * properly indicate image capture or recording start/stop to the user.</p> 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 654bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param cb a callback object that receives a copy of the next preview frame, 655bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or null to stop receiving callbacks. 656108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.media.MediaActionSound 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void setOneShotPreviewCallback(PreviewCallback cb) { 65994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mPreviewCallback = cb; 66094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mOneShot = true; 66194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mWithBuffer = false; 6627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (cb != null) { 6637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = false; 6647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 66594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp setHasPreviewCallback(cb != null, false); 66694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp } 66794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp 66894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); 66994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp 67094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp /** 671108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>Installs a callback to be invoked for every preview frame, using 672108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to 673bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * displaying them on the screen. The callback will be repeatedly called 674108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * for as long as preview is active and buffers are available. Any other 675108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * preview callbacks are overridden.</p> 67694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp * 677bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>The purpose of this method is to improve preview efficiency and frame 678bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * rate by allowing preview frame memory reuse. You must call 679bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #addCallbackBuffer(byte[])} at some point -- before or after 680108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * calling this method -- or no callbacks will received.</p> 68194927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp * 682108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>The buffer queue will be cleared if this method is called with a null 683bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called, 684108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is 685108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * called.</p> 686108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * 687108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>If you are using the preview data to create video or still images, 688108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * strongly consider using {@link android.media.MediaActionSound} to 689108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * properly indicate image capture or recording start/stop to the user.</p> 69094927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp * 691bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param cb a callback object that receives a copy of the preview frame, 692bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or null to stop receiving callbacks and clear the buffer queue. 693bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #addCallbackBuffer(byte[]) 694108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.media.MediaActionSound 69594927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp */ 69694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { 69794927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mPreviewCallback = cb; 69894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mOneShot = false; 69994927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp mWithBuffer = true; 7007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (cb != null) { 7017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = false; 7027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 70394927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp setHasPreviewCallback(cb != null, true); 7049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 70694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp /** 7073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * Adds a pre-allocated buffer to the preview callback buffer queue. 7083f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * Applications can add one or more buffers to the queue. When a preview 709bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * frame arrives and there is still at least one available buffer, the 710bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * buffer will be used and removed from the queue. Then preview callback is 711bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * invoked with the buffer. If a frame arrives and there is no buffer left, 712bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * the frame is discarded. Applications should add buffers back when they 713bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * finish processing the data in them. 714c10275abd6a494c93a025f683dde104a5d4f2793Wu-cheng Li * 715951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>For formats besides YV12, the size of the buffer is determined by 716951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * multiplying the preview image width, height, and bytes per pixel. The 717951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * width and height can be read from 718951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be 719951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 720951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 8, using the image format from 721951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link Camera.Parameters#getPreviewFormat()}. 722951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 723951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the 724951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * size can be calculated using the equations listed in 725951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link Camera.Parameters#setPreviewFormat}. 72694927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp * 727bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This method is only necessary when 728e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When 729bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setPreviewCallback(PreviewCallback)} or 730bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers 731e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * are automatically allocated. When a supplied buffer is too small to 732e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * hold the preview frame data, preview callback will return null and 733e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * the buffer will be removed from the buffer queue. 73494927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp * 735951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @param callbackBuffer the buffer to add to the queue. The size of the 736951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * buffer must match the values described above. 7375b9bcda3a26e9b1f9b1eff28a2be8853d69614f0Wu-cheng Li * @see #setPreviewCallbackWithBuffer(PreviewCallback) 73894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp */ 739e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong public final void addCallbackBuffer(byte[] callbackBuffer) 740e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong { 741e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME); 742e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 743e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 744e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong /** 745e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * Adds a pre-allocated buffer to the raw image callback buffer queue. 746e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * Applications can add one or more buffers to the queue. When a raw image 747e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * frame arrives and there is still at least one available buffer, the 748e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * buffer will be used to hold the raw image data and removed from the 749e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * queue. Then raw image callback is invoked with the buffer. If a raw 750e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * image frame arrives but there is no buffer left, the frame is 751e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * discarded. Applications should add buffers back when they finish 752e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * processing the data in them by calling this method again in order 753e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * to avoid running out of raw image callback buffers. 754e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 755e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * <p>The size of the buffer is determined by multiplying the raw image 756e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * width, height, and bytes per pixel. The width and height can be 757e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel 758e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * can be computed from 759e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, 760e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * using the image format from {@link Camera.Parameters#getPreviewFormat()}. 761e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 762e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * <p>This method is only necessary when the PictureCallbck for raw image 763e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * is used while calling {@link #takePicture(Camera.ShutterCallback, 764e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. 765e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 76632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Please note that by calling this method, the mode for 76732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * application-managed callback buffers is triggered. If this method has 76832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * never been called, null will be returned by the raw image callback since 76932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * there is no image callback buffer available. Furthermore, When a supplied 77032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * buffer is too small to hold the raw image data, raw image callback will 77132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * return null and the buffer will be removed from the buffer queue. 772e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 773e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * @param callbackBuffer the buffer to add to the raw image callback buffer 774e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * queue. The size should be width * height * (bits per pixel) / 8. An 775e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * null callbackBuffer will be ignored and won't be added to the queue. 776e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 777e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * @see #takePicture(Camera.ShutterCallback, 778e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. 779e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * 780e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * {@hide} 781e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong */ 782e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong public final void addRawImageCallbackBuffer(byte[] callbackBuffer) 783e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong { 784e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE); 785e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 786e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 787e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong private final void addCallbackBuffer(byte[] callbackBuffer, int msgType) 788e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong { 789e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong // CAMERA_MSG_VIDEO_FRAME may be allowed in the future. 790e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong if (msgType != CAMERA_MSG_PREVIEW_FRAME && 791e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong msgType != CAMERA_MSG_RAW_IMAGE) { 792e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong throw new IllegalArgumentException( 793e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong "Unsupported message type: " + msgType); 794e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 795e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 796e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong _addCallbackBuffer(callbackBuffer, msgType); 797e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 798e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 799e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong private native final void _addCallbackBuffer( 800e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong byte[] callbackBuffer, int msgType); 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala /** 8037005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>Create a {@link android.renderscript RenderScript} 8047005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link android.renderscript.Allocation Allocation} to use as a 8057005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * destination of preview callback frames. Use 8067005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use 8077005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * the created Allocation as a destination for camera preview frames.</p> 8087005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8097005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>The Allocation will be created with a YUV type, and its contents must 8107005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * be accessed within Renderscript with the {@code rsGetElementAtYuv_*} 8117005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * accessor methods. Its size will be based on the current 8127005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link Parameters#getPreviewSize preview size} configured for this 8137005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * camera.</p> 8147005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8157005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @param rs the RenderScript context for this Allocation. 8167005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @param usage additional usage flags to set for the Allocation. The usage 8177005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always 8187005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * be set on the created Allocation, but additional flags may be provided 8197005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * here. 8207005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @return a new YUV-type Allocation with dimensions equal to the current 8217005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * preview size. 8227005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @throws RSIllegalArgumentException if the usage flags are not compatible 8237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * with an YUV Allocation. 8247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @see #setPreviewCallbackAllocation 8257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @hide 8267005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala */ 8277005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala public final Allocation createPreviewAllocation(RenderScript rs, int usage) 8287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throws RSIllegalArgumentException { 8297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Parameters p = getParameters(); 8307005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Size previewSize = p.getPreviewSize(); 8317005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Type.Builder yuvBuilder = new Type.Builder(rs, 8327005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Element.createPixel(rs, 8337005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Element.DataType.UNSIGNED_8, 8347005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Element.DataKind.PIXEL_YUV)); 8357005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala // Use YV12 for wide compatibility. Changing this requires also 8367005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala // adjusting camera service's format selection. 8377005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala yuvBuilder.setYuvFormat(ImageFormat.YV12); 8387005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala yuvBuilder.setX(previewSize.width); 8397005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala yuvBuilder.setY(previewSize.height); 8407005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 8417005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Allocation a = Allocation.createTyped(rs, yuvBuilder.create(), 8427005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala usage | Allocation.USAGE_IO_INPUT); 8437005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 8447005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala return a; 8457005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 8467005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 8477005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala /** 8487005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>Set an {@link android.renderscript.Allocation Allocation} as the 8497005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * target of preview callback data. Use this method for efficient processing 8507005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * of camera preview data with RenderScript. The Allocation must be created 8517005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * with the {@link #createPreviewAllocation createPreviewAllocation } 8527005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * method.</p> 8537005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8547005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>Setting a preview allocation will disable any active preview callbacks 8557005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * set by {@link #setPreviewCallback setPreviewCallback} or 8567005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and 8577005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * vice versa. Using a preview allocation still requires an active standard 8587005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * preview target to be set, either with 8597005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link #setPreviewTexture setPreviewTexture} or 8607005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link #setPreviewDisplay setPreviewDisplay}.</p> 8617005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8627005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>To be notified when new frames are available to the Allocation, use 8637005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To 8647005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * update the frame currently accessible from the Allocation to the latest 8657005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * preview frame, call 8667005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p> 8677005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8687005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>To disable preview into the Allocation, call this method with a 8697005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@code null} parameter.</p> 8707005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8717005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>Once a preview allocation is set, the preview size set by 8727005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If 8737005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * you wish to change the preview size, first remove the preview allocation 8747005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * by calling {@code setPreviewCallbackAllocation(null)}, then change the 8757005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * preview size, create a new preview Allocation with 8767005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * {@link #createPreviewAllocation createPreviewAllocation}, and set it as 8777005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * the new preview callback allocation target.</p> 8787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * <p>If you are using the preview data to create video or still images, 8807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * strongly consider using {@link android.media.MediaActionSound} to 8817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * properly indicate image capture or recording start/stop to the user.</p> 8827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * 8837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @param previewAllocation the allocation to use as destination for preview 8847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @throws IOException if configuring the camera to use the Allocation for 8857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * preview fails. 8867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @throws IllegalArgumentException if the Allocation's dimensions or other 8877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * parameters don't meet the requirements. 8887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @see #createPreviewAllocation 8897005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @see #setPreviewCallback 8907005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @see #setPreviewCallbackWithBuffer 8917005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala * @hide 8927005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala */ 8937005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala public final void setPreviewCallbackAllocation(Allocation previewAllocation) 8947005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throws IOException { 8957005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Surface previewSurface = null; 8967005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (previewAllocation != null) { 8977005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Parameters p = getParameters(); 8987005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Size previewSize = p.getPreviewSize(); 8997005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (previewSize.width != previewAllocation.getType().getX() || 9007005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala previewSize.height != previewAllocation.getType().getY()) { 9017005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throw new IllegalArgumentException( 9027005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala "Allocation dimensions don't match preview dimensions: " + 9037005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala "Allocation is " + 9047005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala previewAllocation.getType().getX() + 9057005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala ", " + 9067005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala previewAllocation.getType().getY() + 9077005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala ". Preview is " + previewSize.width + ", " + 9087005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala previewSize.height); 9097005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 9107005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if ((previewAllocation.getUsage() & 9117005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Allocation.USAGE_IO_INPUT) == 0) { 9127005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throw new IllegalArgumentException( 9137005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala "Allocation usage does not include USAGE_IO_INPUT"); 9147005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 9157005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (previewAllocation.getType().getElement().getDataKind() != 9167005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Element.DataKind.PIXEL_YUV) { 9177005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throw new IllegalArgumentException( 9187005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala "Allocation is not of a YUV type"); 9197005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 9207005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala previewSurface = previewAllocation.getSurface(); 9217005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = true; 9227005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } else { 9237005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala mUsingPreviewAllocation = false; 9247005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 9257005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala setPreviewCallbackSurface(previewSurface); 9267005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 9277005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 9287005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala private native final void setPreviewCallbackSurface(Surface s); 9297005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 9309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private class EventHandler extends Handler 9319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Camera mCamera; 9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public EventHandler(Camera c, Looper looper) { 9359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super(looper); 9369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mCamera = c; 9379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 9409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void handleMessage(Message msg) { 9419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(msg.what) { 942c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_SHUTTER: 9439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mShutterCallback != null) { 9449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mShutterCallback.onShutter(); 9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 947c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks 948c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_RAW_IMAGE: 949e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks if (mRawImageCallback != null) { 9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); 951e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 9529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 9539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 954c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_COMPRESSED_IMAGE: 955e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks if (mJpegCallback != null) { 9569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); 957e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 9599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 960c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_PREVIEW_FRAME: 961ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala PreviewCallback pCb = mPreviewCallback; 962ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala if (pCb != null) { 9639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOneShot) { 964a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // Clear the callback variable before the callback 965a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // in case the app calls setPreviewCallback from 966a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // the callback function 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPreviewCallback = null; 96894927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp } else if (!mWithBuffer) { 969a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // We're faking the camera preview mode to prevent 970a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // the app from being flooded with preview frames. 971a6118c6383c6f5703a576d08586a340fd71d28a4Dave Sparks // Set to oneshot mode again. 97294927dffce1626898b59579dfc5af53b5de8cef6Andrew Harp setHasPreviewCallback(true, false); 9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 974ca367b717806c4c69190641c3361d3520a44ad08Eino-Ville Talvala pCb.onPreviewFrame((byte[])msg.obj, mCamera); 9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 978e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks case CAMERA_MSG_POSTVIEW_FRAME: 979e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks if (mPostviewCallback != null) { 980e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); 981e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 982e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks return; 983e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks 984c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_FOCUS: 985f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li AutoFocusCallback cb = null; 986f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li synchronized (mAutoFocusCallbackLock) { 987f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li cb = mAutoFocusCallback; 988f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li } 989f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li if (cb != null) { 990f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li boolean success = msg.arg1 == 0 ? false : true; 991f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li cb.onAutoFocus(success, mCamera); 992e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 993e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks return; 994e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks 995e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks case CAMERA_MSG_ZOOM: 9963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li if (mZoomListener != null) { 9973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); 998e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 9999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 10009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1001bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li case CAMERA_MSG_PREVIEW_METADATA: 10024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li if (mFaceListener != null) { 1003f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li mFaceListener.onFaceDetection((Face[])msg.obj, mCamera); 10044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 10054c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li return; 10064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 1007c62f9bd13327937aa2d2f20b44215397120634c1Dave Sparks case CAMERA_MSG_ERROR : 10089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Error " + msg.arg1); 1009e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks if (mErrorCallback != null) { 10109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mErrorCallback.onError(msg.arg1, mCamera); 1011e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 10129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10149d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li case CAMERA_MSG_FOCUS_MOVE: 10159d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li if (mAutoFocusMoveCallback != null) { 10169d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera); 10179d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li } 10189d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li return; 10199d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li 10209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project default: 10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Unknown message type " + msg.what); 10229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 10239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static void postEventFromNative(Object camera_ref, 10289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int what, int arg1, int arg2, Object obj) 10299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Camera c = (Camera)((WeakReference)camera_ref).get(); 10319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (c == null) 10329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 10339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (c.mEventHandler != null) { 10359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); 10369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project c.mEventHandler.sendMessage(m); 10379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1041bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface used to notify on completion of camera auto focus. 1042bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 10437478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * <p>Devices that do not support auto-focus will receive a "fake" 10447478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * callback to this interface. If your application needs auto-focus and 1045df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * should not be installed on devices <em>without</em> auto-focus, you must 1046df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * declare that your app uses the 10477478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * {@code android.hardware.camera.autofocus} feature, in the 1048df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> 1049df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * manifest element.</p> 1050bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1051bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #autoFocus(AutoFocusCallback) 10529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface AutoFocusCallback 10549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 105669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * Called when the camera auto focus completes. If the camera 105769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * does not support auto-focus and autoFocus is called, 105869ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * onAutoFocus will be called immediately with a fake value of 105969ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * <code>success</code> set to <code>true</code>. 10609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 1061b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * The auto-focus routine does not lock auto-exposure and auto-white 1062b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * balance after it completes. 106383d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * 10649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param success true if focus was successful, false if otherwise 10659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param camera the Camera service object 106683d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) 106783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) 10689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onAutoFocus(boolean success, Camera camera); 107053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li } 10719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1073bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Starts camera auto-focus and registers a callback function to run when 1074bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * the camera is focused. This method is only valid when preview is active 1075bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * (between {@link #startPreview()} and before {@link #stopPreview()}). 1076bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1077bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>Callers should check 1078bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if 1079bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * this method should be called. If the camera does not support auto-focus, 1080bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} 108136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * callback will be called immediately. 1082bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1083da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main * <p>If your application should not be installed 10847478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * on devices without auto-focus, you must declare that your application 10857478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * uses auto-focus with the 1086df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> 1087df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * manifest element.</p> 1088bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1089068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * <p>If the current flash mode is not 1090068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be 1091bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * fired during auto-focus, depending on the driver and camera hardware.<p> 10927478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * 109353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()} 1094b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()} 1095b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * do not change during and after autofocus. But auto-focus routine may stop 1096b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * auto-exposure and auto-white balance transiently during focusing. 109783d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * 109853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * <p>Stopping preview with {@link #stopPreview()}, or triggering still 109953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * image capture with {@link #takePicture(Camera.ShutterCallback, 110053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}, will not change the 110153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * the focus position. Applications must call cancelAutoFocus to reset the 110253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * focus.</p> 110353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * 1104108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * <p>If autofocus is successful, consider using 1105108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * {@link android.media.MediaActionSound} to properly play back an autofocus 1106108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * success sound to the user.</p> 1107108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * 11089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param cb the callback to run 1109bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #cancelAutoFocus() 111083d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) 111183d3352cf7a67efd60732c0d40e5928f642f6808Eino-Ville Talvala * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) 1112108708b4873fb05cb029b5bcb29a4e917004ca30Eino-Ville Talvala * @see android.media.MediaActionSound 11139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void autoFocus(AutoFocusCallback cb) 11159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 1116f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li synchronized (mAutoFocusCallbackLock) { 1117248ba23ad28c1f8fb69904663204df08c5818700James Dong mAutoFocusCallback = cb; 1118248ba23ad28c1f8fb69904663204df08c5818700James Dong } 1119f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li native_autoFocus(); 11209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_autoFocus(); 11229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1124bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Cancels any auto-focus function in progress. 1125bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Whether or not auto-focus is currently in progress, 1126bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * this function will return the focus position to the default. 1127244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang * If the camera does not support auto-focus, this is a no-op. 1128bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1129bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #autoFocus(Camera.AutoFocusCallback) 1130244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang */ 1131244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang public final void cancelAutoFocus() 1132244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang { 1133f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li synchronized (mAutoFocusCallbackLock) { 1134248ba23ad28c1f8fb69904663204df08c5818700James Dong mAutoFocusCallback = null; 1135248ba23ad28c1f8fb69904663204df08c5818700James Dong } 1136f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li native_cancelAutoFocus(); 1137f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // CAMERA_MSG_FOCUS should be removed here because the following 1138f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // scenario can happen: 1139f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // - An application uses the same thread for autoFocus, cancelAutoFocus 1140f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // and looper thread. 1141f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // - The application calls autoFocus. 1142f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue. 1143f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // Before event handler's handleMessage() is invoked, the application 1144f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // calls cancelAutoFocus and autoFocus. 1145f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus 1146f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // has been completed. But in fact it is not. 1147f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // 1148f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // As documented in the beginning of the file, apps should not use 1149f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // multiple threads to call autoFocus and cancelAutoFocus at the same 1150f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS 1151f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li // message after native_cancelAutoFocus is called. 1152f05c1d63d16e790ac78c5854bb12374f45d6118eWu-cheng Li mEventHandler.removeMessages(CAMERA_MSG_FOCUS); 1153244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang } 1154244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang private native final void native_cancelAutoFocus(); 1155244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang 1156244f8c26365a303d9dd861bd48a29a4b48578da1Chih-Chung Chang /** 11579d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * Callback interface used to notify on auto focus start and stop. 11589d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * 11596574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li * <p>This is only supported in continuous autofocus modes -- {@link 11606574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link 11616574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show 11626574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li * autofocus animation based on this.</p> 11639d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li */ 11649d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li public interface AutoFocusMoveCallback 11659d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li { 11669d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li /** 11679d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * Called when the camera auto focus starts or stops. 11689d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * 11699d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * @param start true if focus starts to move, false if focus stops to move 11706574539baecc8610529596554b7bca0f21b334b8Wu-cheng Li * @param camera the Camera service object 11719d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li */ 11729d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li void onAutoFocusMoving(boolean start, Camera camera); 11739d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li } 11749d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li 11759d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li /** 11769d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * Sets camera auto-focus move callback. 11779d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * 11789d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li * @param cb the callback to run 11799d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li */ 11809d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) { 11819d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li mAutoFocusMoveCallback = cb; 11829d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0); 11839d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li } 11849d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li 11859d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li private native void enableFocusMoveCallback(int enable); 11869d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li 11879d062cfe94dcd24b1d61fc83e5de565cb67965b1Wu-cheng Li /** 1188bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface used to signal the moment of actual image capture. 1189bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1190bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) 11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface ShutterCallback 11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 11949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1195bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Called as near as possible to the moment when a photo is captured 1196bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * from the sensor. This is a good opportunity to play a shutter sound 1197bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or give other feedback of camera operation. This may be some time 1198bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * after the photo was triggered, but some time before the actual data 1199bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * is available. 12009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onShutter(); 12029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1205bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface used to supply image data from a photo capture. 1206bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1207bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) 12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface PictureCallback { 12109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1211bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Called when image data is available after a picture is taken. 1212bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * The format of the data depends on the context of the callback 1213bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * and {@link Camera.Parameters} settings. 12149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 12159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param data a byte array of the picture data 12169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param camera the Camera service object 12179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onPictureTaken(byte[] data, Camera camera); 12199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 12209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1222bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Equivalent to takePicture(shutter, raw, null, jpeg). 12239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 1224bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) 12259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void takePicture(ShutterCallback shutter, PictureCallback raw, 12279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project PictureCallback jpeg) { 1228e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks takePicture(shutter, raw, null, jpeg); 1229e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 1230e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong private native final void native_takePicture(int msgType); 1231e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks 1232e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks /** 12339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Triggers an asynchronous image capture. The camera service will initiate 12349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * a series of callbacks to the application as the image capture progresses. 12359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * The shutter callback occurs after the image is captured. This can be used 12369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * to trigger a sound to let the user know that image has been captured. The 12379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * raw callback occurs when the raw image data is available (NOTE: the data 1238e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * will be null if there is no raw image callback buffer available or the 1239e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong * raw image callback buffer is not large enough to hold the raw image). 12409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * The postview callback occurs when a scaled, fully processed postview 12419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * image is available (NOTE: not all hardware supports this). The jpeg 12429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * callback occurs when the compressed image is available. If the 12439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * application does not need a particular callback, a null can be passed 12449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * instead of a callback method. 1245e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks * 1246bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>This method is only valid when preview is active (after 1247bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link #startPreview()}). Preview will be stopped after the image is 1248bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * taken; callers must call {@link #startPreview()} again if they want to 124942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * re-start preview or take more pictures. This should not be called between 125042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link android.media.MediaRecorder#start()} and 125142419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link android.media.MediaRecorder#stop()}. 125240057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li * 1253bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * <p>After calling this method, you must not call {@link #startPreview()} 1254bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * or take another picture until the JPEG callback has returned. 125540057ce749c8c4d274db0352a2af4344bda92dbaWu-cheng Li * 1256bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param shutter the callback for image capture moment, or null 1257bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param raw the callback for raw (uncompressed) image data, or null 1258e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks * @param postview callback with postview image data, may be null 1259bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param jpeg the callback for JPEG image data, or null 1260e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks */ 1261e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks public final void takePicture(ShutterCallback shutter, PictureCallback raw, 1262e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks PictureCallback postview, PictureCallback jpeg) { 12639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mShutterCallback = shutter; 12649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mRawImageCallback = raw; 1265e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks mPostviewCallback = postview; 12669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mJpegCallback = jpeg; 1267e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 1268e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong // If callback is not set, do not send me callbacks. 1269e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong int msgType = 0; 1270e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong if (mShutterCallback != null) { 1271e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong msgType |= CAMERA_MSG_SHUTTER; 1272e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 1273e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong if (mRawImageCallback != null) { 1274e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong msgType |= CAMERA_MSG_RAW_IMAGE; 1275e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 1276e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong if (mPostviewCallback != null) { 1277e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong msgType |= CAMERA_MSG_POSTVIEW_FRAME; 1278e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 1279e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong if (mJpegCallback != null) { 1280e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong msgType |= CAMERA_MSG_COMPRESSED_IMAGE; 1281e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong } 1282e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong 1283e00cab707dcaf6f05adb5ccb9c80fdf25c483427James Dong native_takePicture(msgType); 1284e9c6c9ccfde7a642a4c0554e2d066f3dbbea98ceWu-cheng Li mFaceDetectionRunning = false; 12859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1287e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks /** 1288bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Zooms to the requested value smoothly. The driver will notify {@link 12893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * OnZoomChangeListener} of the zoom value and whether zoom is stopped at 12903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * the time. For example, suppose the current zoom is 0 and startSmoothZoom 1291bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * is called with value 3. The 1292bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)} 1293bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * method will be called three times with zoom values 1, 2, and 3. 1294bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. 1295bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Applications should not call startSmoothZoom again or change the zoom 1296bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * value before zoom stops. If the supplied zoom value equals to the current 1297bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * zoom value, no zoom callback will be generated. This method is supported 1298bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported} 1299bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * returns true. 130036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 130136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @param value zoom value. The valid range is 0 to {@link 130236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * android.hardware.Camera.Parameters#getMaxZoom}. 13030ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li * @throws IllegalArgumentException if the zoom value is invalid. 13040ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li * @throws RuntimeException if the method fails. 1305bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setZoomChangeListener(OnZoomChangeListener) 130636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 130736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public native final void startSmoothZoom(int value); 130836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 130936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 1310bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Stops the smooth zoom. Applications should wait for the {@link 13113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * OnZoomChangeListener} to know when the zoom is actually stopped. This 13123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * method is supported if {@link 13138cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. 13140ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li * 13150ca25191c663ef229f1f475b17899f2017ed6980Wu-cheng Li * @throws RuntimeException if the method fails. 131636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 131736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public native final void stopSmoothZoom(); 131836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 131936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 13202fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * Set the clockwise rotation of preview display in degrees. This affects 13212fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * the preview frames and the picture displayed after snapshot. This method 13222fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * is useful for portrait mode applications. Note that preview display of 1323b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li * front-facing cameras is flipped horizontally before the rotation, that 1324b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li * is, the image is reflected along the central vertical axis of the camera 1325b982fb4fd36a3cd24a0bb17c964139fe4c9cbb47Wu-cheng Li * sensor. So the users can see themselves as looking into a mirror. 1326d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang * 132769ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * <p>This does not affect the order of byte array passed in {@link 13282fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This 13292fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * method is not allowed to be called during preview. 1330d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang * 133169ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * <p>If you want to make the camera image show in the same orientation as 133269ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * the display, you can use the following code. 1333b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * <pre> 1334724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * public static void setCameraDisplayOrientation(Activity activity, 1335724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * int cameraId, android.hardware.Camera camera) { 1336724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * android.hardware.Camera.CameraInfo info = 1337724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * new android.hardware.Camera.CameraInfo(); 1338724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * android.hardware.Camera.getCameraInfo(cameraId, info); 1339724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * int rotation = activity.getWindowManager().getDefaultDisplay() 1340724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * .getRotation(); 1341724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * int degrees = 0; 1342724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * switch (rotation) { 1343724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * case Surface.ROTATION_0: degrees = 0; break; 1344724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * case Surface.ROTATION_90: degrees = 90; break; 1345724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * case Surface.ROTATION_180: degrees = 180; break; 1346724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * case Surface.ROTATION_270: degrees = 270; break; 1347724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * } 1348b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * 13492fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * int result; 13502fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 13512fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * result = (info.orientation + degrees) % 360; 13522fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * result = (360 - result) % 360; // compensate the mirror 13532fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } else { // back-facing 13542fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * result = (info.orientation - degrees + 360) % 360; 13552fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } 1356724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * camera.setDisplayOrientation(result); 1357724c52244423feced2677fbd1f905e0b8b0639f2Chih-Chung Chang * } 1358b8bb78f54b48868465a9d69d65fda08524ab5ae1Chih-Chung Chang * </pre> 1359d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li * 1360d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li * <p>Starting from API level 14, this method can be called when preview is 1361d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li * active. 1362d303362ac21fb9de40f2f2366cbe7ecaa113dc12Wu-cheng Li * 1363d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang * @param degrees the angle that the picture will be rotated clockwise. 1364e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang * Valid values are 0, 90, 180, and 270. The starting 1365e7bd22a9d9441916aa9c67d80ee9f02a2d3e10e5Chih-Chung Chang * position is 0 (landscape). 13662fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * @see #setPreviewDisplay(SurfaceHolder) 1367d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang */ 1368d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang public native final void setDisplayOrientation(int degrees); 1369d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang 1370d1d7706fce19a9a0cf71ff9b65f3aba9b89eeb3bChih-Chung Chang /** 1371487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * <p>Enable or disable the default shutter sound when taking a picture.</p> 137269fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * 1373487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * <p>By default, the camera plays the system-defined camera shutter sound 1374487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * when {@link #takePicture} is called. Using this method, the shutter sound 1375487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * can be disabled. It is strongly recommended that an alternative shutter 1376487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * sound is played in the {@link ShutterCallback} when the system shutter 1377487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * sound is disabled.</p> 137869fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * 1379487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * <p>Note that devices may not always allow disabling the camera shutter 1380487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * sound. If the shutter sound state cannot be set to the desired value, 1381487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * this method will return false. {@link CameraInfo#canDisableShutterSound} 1382487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * can be used to determine whether the device will allow the shutter sound 1383487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * to be disabled.</p> 138469fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * 138569fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * @param enabled whether the camera should play the system shutter sound 138669fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * when {@link #takePicture takePicture} is called. 1387487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * @return {@code true} if the shutter sound state was successfully 1388487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * changed. {@code false} if the shutter sound state could not be 1389487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * changed. {@code true} is also returned if shutter sound playback 1390487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * is already set to the requested state. 139169fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * @see #takePicture 1392487acdfb4eca3859fd688a1ff0a32fe6314b68f6Eino-Ville Talvala * @see CameraInfo#canDisableShutterSound 139369fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala * @see ShutterCallback 139469fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala */ 13954f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala public final boolean enableShutterSound(boolean enabled) { 13964f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala if (!enabled) { 13974f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); 13984f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala IAudioService audioService = IAudioService.Stub.asInterface(b); 13994f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala try { 14004f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala if (audioService.isCameraSoundForced()) return false; 14014f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } catch (RemoteException e) { 14024f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala Log.e(TAG, "Audio service is unavailable for queries"); 14034f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 14044f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 14054f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala return _enableShutterSound(enabled); 14064f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala } 14074f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala 14084f8e5ce21df881796d05a1b2117dd8868570a57bEino-Ville Talvala private native final boolean _enableShutterSound(boolean enabled); 140969fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala 141069fe527bea12f262bfb1a5838f40e3433ad3cb78Eino-Ville Talvala /** 1411bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface for zoom changes during a smooth zoom operation. 1412bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1413bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setZoomChangeListener(OnZoomChangeListener) 1414bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #startSmoothZoom(int) 1415e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks */ 14163f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li public interface OnZoomChangeListener 1417e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks { 1418e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks /** 1419bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Called when the zoom value has changed during a smooth zoom. 142036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 142136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @param zoomValue the current zoom value. In smooth zoom mode, camera 14223f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * calls this for every new zoom value. 142336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @param stopped whether smooth zoom is stopped. If the value is true, 142436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * this is the last zoom update for the application. 1425e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks * @param camera the Camera service object 1426e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks */ 14273f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li void onZoomChange(int zoomValue, boolean stopped, Camera camera); 1428e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks }; 1429e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks 1430e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks /** 14313f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * Registers a listener to be notified when the zoom value is updated by the 143236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * camera driver during smooth zoom. 14338cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * 14343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param listener the listener to notify 14358cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * @see #startSmoothZoom(int) 1436e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks */ 14373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li public final void setZoomChangeListener(OnZoomChangeListener listener) 1438e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks { 14393f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li mZoomListener = listener; 1440e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8abDave Sparks } 14419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 14424c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 14434c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Callback interface for face detected in the preview frame. 14444c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 14454c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 14464c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li public interface FaceDetectionListener 14474c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li { 14484c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 14494c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Notify the listener of the detected faces in the preview frame. 14504c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 145153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * @param faces The detected faces in a list 1452464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @param camera The {@link Camera} service object 14534c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 1454f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li void onFaceDetection(Face[] faces, Camera camera); 14554c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 14564c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 14574c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 1458c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Registers a listener to be notified about the faces detected in the 14594c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * preview frame. 14604c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 14614c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @param listener the listener to notify 1462c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * @see #startFaceDetection() 14634c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 14644c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li public final void setFaceDetectionListener(FaceDetectionListener listener) 14654c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li { 14664c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li mFaceListener = listener; 14674c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 14684c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 14694c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 1470c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Starts the face detection. This should be called after preview is started. 14714c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * The camera will notify {@link FaceDetectionListener} of the detected 14724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * faces in the preview frame. The detected faces may be the same as the 14734c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * previous ones. Applications should call {@link #stopFaceDetection} to 14744c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * stop the face detection. This method is supported if {@link 1475c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. 14764c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * If the face detection has started, apps should not call this again. 14774c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 14788c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, 14794c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} 14808c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * have no effect. The camera uses the detected faces to do auto-white balance, 14818c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * auto exposure, and autofocus. 14828c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * 14838c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera 14848c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * will stop sending face callbacks. The last face callback indicates the 14858c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * areas used to do autofocus. After focus completes, face detection will 14868c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * resume sending face callbacks. If the apps call {@link 14878c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * #cancelAutoFocus()}, the face callbacks will also resume.</p> 14888c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * 14898c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, 14908c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming 14918c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * preview with {@link #startPreview()}, the apps should call this method 14928c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * again to resume face detection.</p> 14934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 1494c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * @throws IllegalArgumentException if the face detection is unsupported. 14954c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @throws RuntimeException if the method fails or the face detection is 14964c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * already running. 14974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @see FaceDetectionListener 14984c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @see #stopFaceDetection() 1499c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * @see Parameters#getMaxNumDetectedFaces() 15004c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 1501c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li public final void startFaceDetection() { 15024c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li if (mFaceDetectionRunning) { 15034c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li throw new RuntimeException("Face detection is already running"); 15044c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 1505c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li _startFaceDetection(CAMERA_FACE_DETECTION_HW); 15064c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li mFaceDetectionRunning = true; 15074c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 15084c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 15094c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 1510c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Stops the face detection. 15114c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 1512464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see #startFaceDetection() 15134c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 15144c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li public final void stopFaceDetection() { 15154c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li _stopFaceDetection(); 15164c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li mFaceDetectionRunning = false; 15174c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 15184c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 15194c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li private native final void _startFaceDetection(int type); 15204c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li private native final void _stopFaceDetection(); 15214c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 15224c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 1523464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * Information about a face identified through camera face detection. 152453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * 1525464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a 1526464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * list of face objects for use in focusing and metering.</p> 15274c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 1528464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see FaceDetectionListener 15294c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 1530f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li public static class Face { 1531c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li /** 1532c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * Create an empty face. 1533c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li */ 1534bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li public Face() { 1535bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li } 1536bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li 15374c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 15384c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Bounds of the face. (-1000, -1000) represents the top-left of the 15394c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * camera field of view, and (1000, 1000) represents the bottom-right of 1540c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * the field of view. For example, suppose the size of the viewfinder UI 1541c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). 15428c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * The corresponding viewfinder rect should be (0, 0, 400, 240). It is 15438c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * guaranteed left < right and top < bottom. The coordinates can be 15448c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * smaller than -1000 or bigger than 1000. But at least one vertex will 15458c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * be within (-1000, -1000) and (1000, 1000). 1546f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li * 1547f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li * <p>The direction is relative to the sensor orientation, that is, what 1548f0d6a48c6ad852b84687127f14b1ffde02416dc4Wu-cheng Li * the sensor sees. The direction is not affected by the rotation or 15498c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * mirroring of {@link #setDisplayOrientation(int)}. The face bounding 15508c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * rectangle does not provide any information about face orientation.</p> 15518c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * 15528c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * <p>Here is the matrix to convert driver coordinates to View coordinates 15538c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * in pixels.</p> 15548c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * <pre> 15558c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * Matrix matrix = new Matrix(); 15568c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; 15578c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * // Need mirror for front camera. 15588c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); 15598c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * matrix.setScale(mirror ? -1 : 1, 1); 15608c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * // This is the value for android.hardware.Camera.setDisplayOrientation. 15618c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * matrix.postRotate(displayOrientation); 15628c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). 15638c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * // UI coordinates range from (0, 0) to (width, height). 15648c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); 15658c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); 15668c13670c13a7a965884d92193b039e26c96b95c6Wu-cheng Li * </pre> 15674c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 1568464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see #startFaceDetection() 15694c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 1570bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li public Rect rect; 15714c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 15724c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 15738df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * <p>The confidence level for the detection of the face. The range is 1 to 15748df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * 100. 100 is the highest confidence.</p> 15758df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * 15768df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * <p>Depending on the device, even very low-confidence faces may be 15778df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * listed, so applications should filter out faces with low confidence, 15788df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * depending on the use case. For a typical point-and-shoot camera 15798df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * application that wishes to display rectangles around detected faces, 15808df3b2b3989df44953153603681e03140fd853d6Eino-Ville Talvala * filtering out faces with confidence less than 50 is recommended.</p> 15814c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 1582464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see #startFaceDetection() 15834c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 1584bb1e275c0e684dd213f124da77110cdd9d6f090cWu-cheng Li public int score; 1585d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua 1586d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua /** 1587d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * An unique id per face while the face is visible to the tracker. If 1588d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * the face leaves the field-of-view and comes back, it will get a new 1589d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * id. This is an optional field, may not be supported on all devices. 1590d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * If not supported, id will always be set to -1. The optional fields 1591d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * are supported as a set. Either they are all valid, or none of them 1592d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * are. 1593d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua */ 1594d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua public int id = -1; 1595d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua 1596d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua /** 1597d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * The coordinates of the center of the left eye. The coordinates are in 1598d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * the same space as the ones for {@link #rect}. This is an optional 1599d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * field, may not be supported on all devices. If not supported, the 1600d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * value will always be set to null. The optional fields are supported 1601d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * as a set. Either they are all valid, or none of them are. 1602d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua */ 1603d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua public Point leftEye = null; 1604d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua 1605d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua /** 1606d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * The coordinates of the center of the right eye. The coordinates are 1607d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * in the same space as the ones for {@link #rect}.This is an optional 1608d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * field, may not be supported on all devices. If not supported, the 1609d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * value will always be set to null. The optional fields are supported 1610d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * as a set. Either they are all valid, or none of them are. 1611d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua */ 1612d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua public Point rightEye = null; 1613d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua 1614d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua /** 1615d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * The coordinates of the center of the mouth. The coordinates are in 1616d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * the same space as the ones for {@link #rect}. This is an optional 1617d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * field, may not be supported on all devices. If not supported, the 1618d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * value will always be set to null. The optional fields are supported 1619d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua * as a set. Either they are all valid, or none of them are. 1620d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua */ 1621d52b308916d5f207791788e00bc48baecb90d8b8Wei Hua public Point mouth = null; 16224c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 16234c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 1624bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor // Error codes match the enum in include/ui/Camera.h 1625bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor 1626bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor /** 1627bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Unspecified camera error. 1628bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see Camera.ErrorCallback 1629bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor */ 16309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAMERA_ERROR_UNKNOWN = 1; 1631bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor 1632bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor /** 1633bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Media server died. In this case, the application must release the 1634bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera object and instantiate a new one. 1635bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see Camera.ErrorCallback 1636bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor */ 16379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAMERA_ERROR_SERVER_DIED = 100; 16389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 16399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1640bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Callback interface for camera error notification. 1641bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1642bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setErrorCallback(ErrorCallback) 16439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 16449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface ErrorCallback 16459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 16469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 16479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Callback for camera errors. 16489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param error error code: 16499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 16509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #CAMERA_ERROR_UNKNOWN} 16519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #CAMERA_ERROR_SERVER_DIED} 16529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 16539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param camera the Camera service object 16549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 16559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onError(int error, Camera camera); 16569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 16579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 16589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 16599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Registers a callback to be invoked when an error occurs. 1660bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @param cb The callback to run 16619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 16629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final void setErrorCallback(ErrorCallback cb) 16639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 16649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mErrorCallback = cb; 16659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 16669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 16679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_setParameters(String params); 16689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final String native_getParameters(); 16699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 16709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1671bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Changes the settings for this Camera service. 16729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 16739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param params the Parameters to use for this Camera service 167499a3f3e4e06b4370101ca97cc11dbe81d772fefaWu-cheng Li * @throws RuntimeException if any parameter is invalid or not supported. 1675bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #getParameters() 16769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 16779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setParameters(Parameters params) { 16787005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala // If using preview allocations, don't allow preview size changes 16797005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (mUsingPreviewAllocation) { 16807005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Size newPreviewSize = params.getPreviewSize(); 16817005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala Size currentPreviewSize = getParameters().getPreviewSize(); 16827005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala if (newPreviewSize.width != currentPreviewSize.width || 16837005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala newPreviewSize.height != currentPreviewSize.height) { 16847005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala throw new IllegalStateException("Cannot change preview size" + 16857005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala " while a preview allocation is configured."); 16867005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 16877005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala } 16887005b67c127d229017840925d2bc1bd84c43aaf5Eino-Ville Talvala 16899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_setParameters(params.flatten()); 16909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 16919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 16929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1693bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Returns the current settings for this Camera service. 1694bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * If modifications are made to the returned Parameters, they must be passed 1695bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * to {@link #setParameters(Camera.Parameters)} to take effect. 1696bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * 1697bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * @see #setParameters(Camera.Parameters) 16989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 16999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Parameters getParameters() { 17009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Parameters p = new Parameters(); 17019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String s = native_getParameters(); 17029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project p.unflatten(s); 17039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return p; 17049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17071c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li * Returns an empty {@link Parameters} for testing purpose. 17081c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li * 1709f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * @return a Parameter object. 17101c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li * 17111c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li * @hide 17121c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li */ 17131c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li public static Parameters getEmptyParameters() { 17141c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li Camera camera = new Camera(); 17151c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li return camera.new Parameters(); 17161c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li } 17171c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li 17181c04a33c040dfb610952d62da9c93a53c291b2d7Wu-cheng Li /** 1719bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Image size (width and height dimensions). 17209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 17219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public class Size { 17229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 17239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the dimensions for pictures. 17249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 17259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param w the photo width (pixels) 17269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param h the photo height (pixels) 17279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 17289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Size(int w, int h) { 17299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project width = w; 17309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project height = h; 17319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 17324c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li /** 17334c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * Compares {@code obj} to this size. 17344c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * 17354c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * @param obj the object to compare this size with. 17364c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * @return {@code true} if the width and height of {@code obj} is the 17374c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * same as those of this size. {@code false} otherwise. 17384c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li */ 17394c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li @Override 17404c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li public boolean equals(Object obj) { 17414c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li if (!(obj instanceof Size)) { 17424c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li return false; 17434c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li } 17444c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li Size s = (Size) obj; 17454c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li return width == s.width && height == s.height; 17464c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li } 17474c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li @Override 17484c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li public int hashCode() { 17494c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li return width * 32713 + height; 17504c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li } 17519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** width of the picture */ 17529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int width; 17539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** height of the picture */ 17549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int height; 17559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 17569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 17579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 175832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The Area class is used for choosing specific metering and focus areas for 175932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the camera to use when calculating auto-exposure, auto-white balance, and 176032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * auto-focus.</p> 176132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * 176232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>To find out how many simultaneous areas a given camera supports, use 176332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * {@link Parameters#getMaxNumMeteringAreas()} and 176432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area 176532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * selection is unsupported, these methods will return 0.</p> 176632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * 176732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Each Area consists of a rectangle specifying its bounds, and a weight 176832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * that determines its importance. The bounds are relative to the camera's 176932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * current field of view. The coordinates are mapped so that (-1000, -1000) 177032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * is always the top-left corner of the current field of view, and (1000, 177132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * 1000) is always the bottom-right corner of the current field of 177232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * view. Setting Areas with bounds outside that range is not allowed. Areas 177332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * with zero or negative width or height are not allowed.</p> 177432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * 177532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The weight must range from 1 to 1000, and represents a weight for 177632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * every pixel in the area. This means that a large metering area with 177732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the same weight as a smaller area will have more effect in the 177832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * metering result. Metering areas can overlap and the driver 177932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * will add the weights in the overlap region.</p> 1780bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * 1781bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#setFocusAreas(List) 1782bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getFocusAreas() 1783bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getMaxNumFocusAreas() 1784bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#setMeteringAreas(List) 1785bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getMeteringAreas() 1786bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getMaxNumMeteringAreas() 178730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 178830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public static class Area { 178930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 179030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Create an area with specified rectangle and weight. 179130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 179232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * @param rect the bounds of the area. 179332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * @param weight the weight of the area. 179430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 179530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public Area(Rect rect, int weight) { 179630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li this.rect = rect; 179730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li this.weight = weight; 179830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 179930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 180030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Compares {@code obj} to this area. 180130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 180230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @param obj the object to compare this area with. 180330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @return {@code true} if the rectangle and weight of {@code obj} is 180430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * the same as those of this area. {@code false} otherwise. 180530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 180630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li @Override 180730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public boolean equals(Object obj) { 180830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (!(obj instanceof Area)) { 180930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return false; 181030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 181130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li Area a = (Area) obj; 181230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (rect == null) { 181330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (a.rect != null) return false; 181430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } else { 181530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (!rect.equals(a.rect)) return false; 181630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 181730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return weight == a.weight; 181830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 181930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 1820bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li /** 182132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * Bounds of the area. (-1000, -1000) represents the top-left of the 182232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * camera field of view, and (1000, 1000) represents the bottom-right of 182332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the field of view. Setting bounds outside that range is not 182432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * allowed. Bounds with zero or negative width or height are not 182532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * allowed. 1826bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * 1827bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getFocusAreas() 1828bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getMeteringAreas() 1829bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li */ 183030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public Rect rect; 183130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 1832bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li /** 183332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * Weight of the area. The weight must range from 1 to 1000, and 183432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * represents a weight for every pixel in the area. This means that a 183532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * large metering area with the same weight as a smaller area will have 183632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * more effect in the metering result. Metering areas can overlap and 183732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * the driver will add the weights in the overlap region. 1838bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * 1839bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getFocusAreas() 1840bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * @see Parameters#getMeteringAreas() 1841bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li */ 184230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public int weight; 1843bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li } 184430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 184530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 1846bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * Camera service settings. 18479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 18489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * <p>To make camera parameters take effect, applications have to call 1849bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link Camera#setParameters(Camera.Parameters)}. For example, after 1850bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not 1851bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * actually changed until {@link Camera#setParameters(Camera.Parameters)} 1852bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * is called with the changed parameters object. 18539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 18549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * <p>Different devices may have different camera capabilities, such as 18559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * picture size or flash modes. The application should query the camera 18569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * capabilities before setting parameters. For example, the application 1857bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * should call {@link Camera.Parameters#getSupportedColorEffects()} before 1858bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * calling {@link Camera.Parameters#setColorEffect(String)}. If the 1859bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * camera does not support color effects, 1860bfcbeffc54e93b1c2e2d95fdc301786df4376d6fDan Egnor * {@link Camera.Parameters#getSupportedColorEffects()} will return null. 18619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 18629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public class Parameters { 18639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Parameter keys to communicate with the camera driver. 18649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_PREVIEW_SIZE = "preview-size"; 18659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_PREVIEW_FORMAT = "preview-format"; 18669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; 1867454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; 18689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_PICTURE_SIZE = "picture-size"; 18699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_PICTURE_FORMAT = "picture-format"; 18704c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; 18719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; 18729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; 18739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; 18749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_JPEG_QUALITY = "jpeg-quality"; 18759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_ROTATION = "rotation"; 18769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_GPS_LATITUDE = "gps-latitude"; 18779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_GPS_LONGITUDE = "gps-longitude"; 18789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_GPS_ALTITUDE = "gps-altitude"; 18799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; 1880055c986ab841f8f758398841730f1e90313b132aRay Chen private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; 18819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_WHITE_BALANCE = "whitebalance"; 18829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_EFFECT = "effect"; 18839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_ANTIBANDING = "antibanding"; 18849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_SCENE_MODE = "scene-mode"; 18859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String KEY_FLASH_MODE = "flash-mode"; 188636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li private static final String KEY_FOCUS_MODE = "focus-mode"; 188730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li private static final String KEY_FOCUS_AREAS = "focus-areas"; 188830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas"; 18896c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li private static final String KEY_FOCAL_LENGTH = "focal-length"; 18906c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; 18916c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; 1892ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; 189324b326a8978bf78e3e560723dde221792784325bWu-cheng Li private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; 189424b326a8978bf78e3e560723dde221792784325bWu-cheng Li private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; 189524b326a8978bf78e3e560723dde221792784325bWu-cheng Li private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; 18963773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock"; 18973773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported"; 1898d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock"; 1899d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported"; 1900e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li private static final String KEY_METERING_AREAS = "metering-areas"; 1901e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas"; 19028cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String KEY_ZOOM = "zoom"; 19038cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String KEY_MAX_ZOOM = "max-zoom"; 19048cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; 19058cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; 19068cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; 1907e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li private static final String KEY_FOCUS_DISTANCES = "focus-distances"; 1908dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong private static final String KEY_VIDEO_SIZE = "video-size"; 1909dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = 1910dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong "preferred-preview-size-for-video"; 19114c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw"; 19124c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw"; 191325d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li private static final String KEY_RECORDING_HINT = "recording-hint"; 191498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported"; 1915037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala private static final String KEY_VIDEO_STABILIZATION = "video-stabilization"; 1916037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported"; 1917e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 19189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Parameter key suffix for supported values. 19199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String SUPPORTED_VALUES_SUFFIX = "-values"; 19209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 19218cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li private static final String TRUE = "true"; 19223773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala private static final String FALSE = "false"; 19238cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li 19249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Values for white balance settings. 19259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_AUTO = "auto"; 19269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; 19279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; 19289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; 19299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; 19309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; 19319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_TWILIGHT = "twilight"; 19329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String WHITE_BALANCE_SHADE = "shade"; 19339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 19349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Values for color effect settings. 19359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_NONE = "none"; 19369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_MONO = "mono"; 19379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_NEGATIVE = "negative"; 19389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_SOLARIZE = "solarize"; 19399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_SEPIA = "sepia"; 19409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_POSTERIZE = "posterize"; 19419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_WHITEBOARD = "whiteboard"; 19429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_BLACKBOARD = "blackboard"; 19439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String EFFECT_AQUA = "aqua"; 19449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 19459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Values for antibanding settings. 19469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String ANTIBANDING_AUTO = "auto"; 19479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String ANTIBANDING_50HZ = "50hz"; 19489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String ANTIBANDING_60HZ = "60hz"; 19499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String ANTIBANDING_OFF = "off"; 19509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 19519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Values for flash mode settings. 19529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 19539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Flash will not be fired. 19549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 19559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String FLASH_MODE_OFF = "off"; 195636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 19579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 1958068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * Flash will be fired automatically when required. The flash may be fired 1959068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * during preview, auto-focus, or snapshot depending on the driver. 19609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 19619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String FLASH_MODE_AUTO = "auto"; 196236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 19639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 1964068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * Flash will always be fired during snapshot. The flash may also be 1965068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * fired during preview or auto-focus depending on the driver. 19669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 19679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String FLASH_MODE_ON = "on"; 196836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 19699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 19709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Flash will be fired in red-eye reduction mode. 19719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 19729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String FLASH_MODE_RED_EYE = "red-eye"; 197336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 197436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 1975068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * Constant emission of light during preview, auto-focus and snapshot. 1976068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li * This can also be used for video recording. 197736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 1978068ef42c3ffe1eccec10f97f08541304f679fe67Wu-cheng Li public static final String FLASH_MODE_TORCH = "torch"; 19799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 198000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 198100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Scene mode is off. 198200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 19839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_AUTO = "auto"; 198400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 198500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 198600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take photos of fast moving objects. Same as {@link 198700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * #SCENE_MODE_SPORTS}. 198800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 19899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_ACTION = "action"; 199000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 199100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 199200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take people pictures. 199300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 19949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_PORTRAIT = "portrait"; 199500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 199600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 199700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take pictures on distant objects. 199800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 19999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_LANDSCAPE = "landscape"; 200000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 200100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 200200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take photos at night. 200300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_NIGHT = "night"; 200500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 200600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 200700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take people pictures at night. 200800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; 201000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 201100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 201200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take photos in a theater. Flash light is off. 201300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_THEATRE = "theatre"; 201500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 201600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 201700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take pictures on the beach. 201800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_BEACH = "beach"; 202000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 202100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 202200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take pictures on the snow. 202300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_SNOW = "snow"; 202500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 202600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 202700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take sunset photos. 202800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_SUNSET = "sunset"; 203000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 203100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 203200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Avoid blurry pictures (for example, due to hand shake). 203300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; 203500e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 203600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 203700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * For shooting firework displays. 203800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_FIREWORKS = "fireworks"; 204000e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 204100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 204200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take photos of fast moving objects. Same as {@link 204300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * #SCENE_MODE_ACTION}. 204400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_SPORTS = "sports"; 204600e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 204700e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 204800e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Take indoor low-light shot. 204900e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20509b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_PARTY = "party"; 205100e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li 205200e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li /** 205300e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li * Capture the naturally warm color of scenes lit by candles. 205400e21f8eb57a7ae2c19516aa0290ab4fb5f251c2Wu-cheng Li */ 20559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; 20569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 2057c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li /** 2058c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * Applications are looking for a barcode. Camera driver will be 2059c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * optimized for barcode reading. 2060c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li */ 2061c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li public static final String SCENE_MODE_BARCODE = "barcode"; 2062c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li 206336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 2064da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * Capture a scene using high dynamic range imaging techniques. The 2065da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * camera will return an image that has an extended dynamic range 2066da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * compared to a regular capture. Capturing such an image may take 2067da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * longer than a regular capture. 2068da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala */ 2069da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala public static final String SCENE_MODE_HDR = "hdr"; 2070da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala 2071da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala /** 2072f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * Auto-focus mode. Applications should call {@link 2073f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * #autoFocus(AutoFocusCallback)} to start the focus in this mode. 207436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 207536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public static final String FOCUS_MODE_AUTO = "auto"; 207636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 207736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 207836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Focus is set at infinity. Applications should not call 207936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * {@link #autoFocus(AutoFocusCallback)} in this mode. 208036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 208136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public static final String FOCUS_MODE_INFINITY = "infinity"; 2082f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li 2083f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li /** 2084f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * Macro (close-up) focus mode. Applications should call 2085f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * {@link #autoFocus(AutoFocusCallback)} to start the focus in this 2086f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * mode. 2087f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li */ 208836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public static final String FOCUS_MODE_MACRO = "macro"; 208936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 209036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 209136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Focus is fixed. The camera is always in this mode if the focus is not 209236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * adjustable. If the camera has auto-focus, this mode can fix the 209336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * focus, which is usually at hyperfocal distance. Applications should 209436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * not call {@link #autoFocus(AutoFocusCallback)} in this mode. 209536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 209636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public static final String FOCUS_MODE_FIXED = "fixed"; 209736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 2098c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li /** 2099c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * Extended depth of field (EDOF). Focusing is done digitally and 2100c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * continuously. Applications should not call {@link 2101c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * #autoFocus(AutoFocusCallback)} in this mode. 2102c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li */ 2103c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li public static final String FOCUS_MODE_EDOF = "edof"; 2104c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li 2105699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li /** 2106d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li * Continuous auto focus mode intended for video recording. The camera 2107b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * continuously tries to focus. This is the best choice for video 2108b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * recording because the focus changes smoothly . Applications still can 2109b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * call {@link #takePicture(Camera.ShutterCallback, 2110b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the 2111b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * subject may not be in focus. Auto focus starts when the parameter is 211253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * set. 211353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * 211453b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * <p>Since API level 14, applications can call {@link 211553b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will 211653b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * immediately return with a boolean that indicates whether the focus is 211753b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * sharp or not. The focus position is locked after autoFocus call. If 211853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * applications want to resume the continuous focus, cancelAutoFocus 211953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * must be called. Restarting the preview will not resume the continuous 212053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * autofocus. To stop continuous focus, applications should change the 212153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * focus mode to other modes. 212253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * 212353b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * @see #FOCUS_MODE_CONTINUOUS_PICTURE 2124d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li */ 2125d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; 2126699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li 2127b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li /** 2128b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * Continuous auto focus mode intended for taking pictures. The camera 2129b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * continuously tries to focus. The speed of focus change is more 2130b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus 213153b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * starts when the parameter is set. 213253b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * 21330f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in 21340f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * this mode. If the autofocus is in the middle of scanning, the focus 21350f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * callback will return when it completes. If the autofocus is not 21360f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * scanning, the focus callback will immediately return with a boolean 21370f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * that indicates whether the focus is sharp or not. The apps can then 21380f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * decide if they want to take a picture immediately or to change the 21390f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * focus mode to auto, and run a full autofocus cycle. The focus 21400f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * position is locked after autoFocus call. If applications want to 21410f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * resume the continuous focus, cancelAutoFocus must be called. 21420f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * Restarting the preview will not resume the continuous autofocus. To 21430f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * stop continuous focus, applications should change the focus mode to 21440f4f97b70f6ad59b32e78720ba7357733bdef3e9Wu-cheng Li * other modes. 2145b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * 2146b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li * @see #FOCUS_MODE_CONTINUOUS_VIDEO 2147b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li */ 2148b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture"; 2149b9ac75d3dfc53ab4a0a104da147f1dfd7bc8c12fWu-cheng Li 2150e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li // Indices for focus distance array. 2151e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li /** 2152e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * The array index of near focus distance for use with 2153e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * {@link #getFocusDistances(float[])}. 2154e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li */ 2155e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; 2156e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 2157e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li /** 2158e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * The array index of optimal focus distance for use with 2159e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * {@link #getFocusDistances(float[])}. 2160e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li */ 2161e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; 2162e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 2163e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li /** 2164e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * The array index of far focus distance for use with 2165e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * {@link #getFocusDistances(float[])}. 2166e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li */ 2167e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li public static final int FOCUS_DISTANCE_FAR_INDEX = 2; 2168e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 2169ca099614841bc619f217dfa088da630a7eb1ab65Wu-cheng Li /** 2170454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * The array index of minimum preview fps for use with {@link 2171454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getPreviewFpsRange(int[])} or {@link 2172454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getSupportedPreviewFpsRange()}. 2173454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2174454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public static final int PREVIEW_FPS_MIN_INDEX = 0; 2175454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2176454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 2177454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * The array index of maximum preview fps for use with {@link 2178454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getPreviewFpsRange(int[])} or {@link 2179454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getSupportedPreviewFpsRange()}. 2180454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2181454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public static final int PREVIEW_FPS_MAX_INDEX = 1; 2182454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 21839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Formats for setPreviewFormat and setPictureFormat. 21849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; 21859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; 2186eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; 218710a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li private static final String PIXEL_FORMAT_YUV420P = "yuv420p"; 21889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String PIXEL_FORMAT_RGB565 = "rgb565"; 21899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private static final String PIXEL_FORMAT_JPEG = "jpeg"; 219070fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb"; 21919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 21927d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin /** 21937d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * Order matters: Keys that are {@link #set(String, String) set} later 21947d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * will take precedence over keys that are set earlier (if the two keys 21957d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * conflict with each other). 21967d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * 21977d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it 21987d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later 21997d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * is the one that will take precedence. 22007d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * </p> 22017d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin */ 22027d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin private final LinkedHashMap<String, String> mMap; 22039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Parameters() { 22057d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64); 22069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Writes the current Parameters to the log. 22109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @hide 22119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @deprecated 22129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void dump() { 22149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "dump: size=" + mMap.size()); 22159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project for (String k : mMap.keySet()) { 22169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); 22179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Creates a single string with all the parameters set in 22229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this Parameters object. 22239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>The {@link #unflatten(String)} method does the reverse.</p> 22249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return a String with all values from this Parameters object, in 22269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * semi-colon delimited key-value pairs 22279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String flatten() { 22290a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen StringBuilder flattened = new StringBuilder(128); 22309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project for (String k : mMap.keySet()) { 22319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(k); 22329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append("="); 22339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(mMap.get(k)); 22349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.append(";"); 22359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // chop off the extra semicolon at the end 22379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project flattened.deleteCharAt(flattened.length()-1); 22389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return flattened.toString(); 22399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Takes a flattened string of parameters and adds each one to 22439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this Parameters object. 22449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>The {@link #flatten()} method does the reverse.</p> 22459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param flattened a String of parameters (key-value paired) that 22479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * are semi-colon delimited 22489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void unflatten(String flattened) { 22509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.clear(); 22519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 22520a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); 22530a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(flattened); 22540a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String kv : splitter) { 22559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int pos = kv.indexOf('='); 22569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (pos == -1) { 22579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project continue; 22589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String k = kv.substring(0, pos); 22609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = kv.substring(pos + 1); 22619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.put(k, v); 22629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 22659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void remove(String key) { 22669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMap.remove(key); 22679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets a String parameter. 22719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 22739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param value the String value of the parameter 22749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void set(String key, String value) { 2276cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) { 2277cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)"); 22789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 22799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2280cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) { 2281cb56923ba6350cf7441260886f6e8a1c6785886dEino-Ville Talvala Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)"); 22829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 22839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22857d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin put(key, value); 22869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 22879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets an integer parameter. 22909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 22919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 22929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param value the int value of the parameter 22939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void set(String key, int value) { 22957d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin put(key, Integer.toString(value)); 22967d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin } 22977d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin 22987d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin private void put(String key, String value) { 22997d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin /* 23007d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * Remove the key if it already exists. 23017d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * 23027d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * This way setting a new value for an already existing key will always move 23037d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin * that key to be ordered the latest in the map. 23047d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin */ 23057d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap.remove(key); 23067d9a8ffd08fa950eb14f8224f6090fe46ab4aa9fIgor Murashkin mMap.put(key, value); 23079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2309e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li private void set(String key, List<Area> areas) { 2310f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (areas == null) { 2311f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li set(key, "(0,0,0,0,0)"); 2312f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } else { 2313f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li StringBuilder buffer = new StringBuilder(); 2314f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li for (int i = 0; i < areas.size(); i++) { 2315f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Area area = areas.get(i); 2316f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Rect rect = area.rect; 2317f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append('('); 2318f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.left); 2319f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2320f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.top); 2321f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2322f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.right); 2323f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2324f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(rect.bottom); 2325f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(','); 2326f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(area.weight); 2327f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li buffer.append(')'); 2328f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (i != areas.size() - 1) buffer.append(','); 2329f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 2330f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li set(key, buffer.toString()); 2331e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 2332e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 2333e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 23349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the value of a String parameter. 23369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 23379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 23389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the String value of the parameter 23399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public String get(String key) { 23419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mMap.get(key); 23429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the value of an integer parameter. 23469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 23479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param key the key name for the parameter 23489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the int value of the parameter 23499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getInt(String key) { 23519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return Integer.parseInt(mMap.get(key)); 23529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 235526274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * Sets the dimensions for preview pictures. If the preview has already 235626274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * started, applications should stop the preview first before changing 235726274fae33b7b056cf5fe9fd6e823cae9e4ddae2Wu-cheng Li * preview size. 23589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 2359c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * The sides of width and height are based on camera orientation. That 2360c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * is, the preview size is the size before it is rotated by display 2361c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * orientation. So applications need to consider the display orientation 2362c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * while setting preview size. For example, suppose the camera supports 2363c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * both 480x320 and 320x480 preview sizes. The application wants a 3:2 2364c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * preview ratio. If the display orientation is set to 0 or 180, preview 2365c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * size should be set to 480x320. If the display orientation is set to 2366c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 90 or 270, preview size should be set to 320x480. The display 2367c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * orientation should also be considered while setting picture size and 2368c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * thumbnail size. 2369c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 23709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the pictures, in pixels 23719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the pictures, in pixels 2372c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setDisplayOrientation(int) 2373c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #getCameraInfo(int, CameraInfo) 2374c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPictureSize(int, int) 2375c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setJpegThumbnailSize(int, int) 23769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewSize(int width, int height) { 23789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = Integer.toString(width) + "x" + Integer.toString(height); 23799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_SIZE, v); 23809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the dimensions setting for preview pictures. 23849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 2385dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return a Size object with the width and height setting 23869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for the preview picture 23879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Size getPreviewSize() { 23899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String pair = get(KEY_PREVIEW_SIZE); 23909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return strToSize(pair); 23919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 23929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 23949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported preview sizes. 23959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 23963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of Size object. This method will always return a list 23979c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li * with at least one element. 23989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 23999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Size> getSupportedPreviewSizes() { 24009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); 24019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitSize(str); 24029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 240532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the supported video frame sizes that can be used by 240632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * MediaRecorder.</p> 2407dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 240832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>If the returned list is not null, the returned list will contain at 2409dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * least one Size and one of the sizes in the returned list must be 2410dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * passed to MediaRecorder.setVideoSize() for camcorder application if 2411dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * camera is used as the video source. In this case, the size of the 2412dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preview can be different from the resolution of the recorded video 241332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * during video recording.</p> 2414dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 2415dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return a list of Size object if camera has separate preview and 2416dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video output; otherwise, null is returned. 2417dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @see #getPreferredPreviewSizeForVideo() 2418dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong */ 2419dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong public List<Size> getSupportedVideoSizes() { 2420dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); 2421dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong return splitSize(str); 2422dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong } 2423dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong 2424dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong /** 2425dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * Returns the preferred or recommended preview size (width and height) 2426dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * in pixels for video recording. Camcorder applications should 2427dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * set the preview size to a value that is not larger than the 2428dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preferred preview size. In other words, the product of the width 2429dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * and height of the preview size should not be larger than that of 2430dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * the preferred preview size. In addition, we recommend to choose a 2431dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * preview size that has the same aspect ratio as the resolution of 2432dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video to be recorded. 2433dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * 2434dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @return the preferred preview size (width and height) in pixels for 2435dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * video recording if getSupportedVideoSizes() does not return 2436dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * null; otherwise, null is returned. 2437dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong * @see #getSupportedVideoSizes() 2438dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong */ 2439dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong public Size getPreferredPreviewSizeForVideo() { 2440dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); 2441dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong return strToSize(pair); 2442dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong } 2443dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong 2444dd0b16c26834d9a58b9865a467c7a26ea14482f3James Dong /** 244532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If 24464c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * applications set both width and height to 0, EXIF will not contain 244732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * thumbnail.</p> 24489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 244932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Applications need to consider the display orientation. See {@link 245032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * #setPreviewSize(int,int)} for reference.</p> 2451c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 24529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the thumbnail, in pixels 24539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the thumbnail, in pixels 2454c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPreviewSize(int,int) 24559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 24569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegThumbnailSize(int width, int height) { 24579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_WIDTH, width); 24589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_HEIGHT, height); 24599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 24609b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 24619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 24629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the dimensions for EXIF thumbnail in Jpeg picture. 24639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return a Size object with the height and width setting for the EXIF 24659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * thumbnails 24669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public Size getJpegThumbnailSize() { 24689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), 24699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); 24709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24734c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * Gets the supported jpeg thumbnail sizes. 24744c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * 24753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of Size object. This method will always return a list 24764c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * with at least two elements. Size 0,0 (no thumbnail) is always 24774c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li * supported. 24784c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li */ 24794c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li public List<Size> getSupportedJpegThumbnailSizes() { 24804c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); 24814c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li return splitSize(str); 24824c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li } 24834c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li 24844c4300c71229638183d814ab8374e09f722910f5Wu-cheng Li /** 24859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the quality of the EXIF thumbnail in Jpeg picture. 24869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 24889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * to 100, with 100 being the best. 24899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegThumbnailQuality(int quality) { 24919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_THUMBNAIL_QUALITY, quality); 24929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 24939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 24949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 24959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the quality setting for the EXIF thumbnail in Jpeg picture. 24969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 24979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return the JPEG quality setting of the EXIF thumbnail. 24989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 24999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public int getJpegThumbnailQuality() { 25009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_JPEG_THUMBNAIL_QUALITY); 25019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 25039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 25049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets Jpeg quality of captured picture. 25059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 25069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param quality the JPEG quality of captured picture. The range is 1 25079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * to 100, with 100 being the best. 25089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 25099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setJpegQuality(int quality) { 25109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_JPEG_QUALITY, quality); 25119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 25129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 25139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 25149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Returns the quality setting for the JPEG picture. 25159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return the JPEG picture quality setting. 25179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 25189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public int getJpegQuality() { 25199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_JPEG_QUALITY); 25209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 25229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2523a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * Sets the rate at which preview frames are received. This is the 2524a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * target frame rate. The actual frame rate depends on the driver. 25259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fps the frame rate (frames per second) 25275f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} 25289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 25295f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 25309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewFrameRate(int fps) { 25319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_FRAME_RATE, fps); 25329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 25349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2535a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * Returns the setting for the rate at which preview frames are 2536a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * received. This is the target frame rate. The actual frame rate 2537a18e90176a8e2442837d0503fbfd4adb9df0818fWu-cheng Li * depends on the driver. 25389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the frame rate setting (frames per second) 25405f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #getPreviewFpsRange(int[])} 25419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 25425f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 25439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPreviewFrameRate() { 25449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return getInt(KEY_PREVIEW_FRAME_RATE); 25459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 25469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 25479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 25489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported preview frame rates. 25499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 25503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported preview frame rates. null if preview 25513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * frame rate setting is not supported. 25525f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} 25539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 25545f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li @Deprecated 25559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPreviewFrameRates() { 25569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); 25579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitInt(str); 25589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 25599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 25609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 25614a68e3c26dd2512c319071dc20074baa6e7d171fHai Guo * Sets the minimum and maximum preview fps. This controls the rate of 25621620d118a49dc6df7b0e83d7343f8a8bb6e23b12Wu-cheng Li * preview frames received in {@link PreviewCallback}. The minimum and 2563454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * maximum preview fps must be one of the elements from {@link 2564454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * #getSupportedPreviewFpsRange}. 2565454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2566454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @param min the minimum preview fps (scaled by 1000). 2567454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @param max the maximum preview fps (scaled by 1000). 2568454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @throws RuntimeException if fps range is invalid. 2569454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) 2570454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #getSupportedPreviewFpsRange() 2571454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2572454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public void setPreviewFpsRange(int min, int max) { 2573454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); 2574454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2575454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2576454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 2577454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * Returns the current minimum and maximum preview fps. The values are 2578454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * one of the elements returned by {@link #getSupportedPreviewFpsRange}. 2579454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2580454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @return range the minimum and maximum preview fps (scaled by 1000). 2581454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MIN_INDEX 2582454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MAX_INDEX 2583454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #getSupportedPreviewFpsRange() 2584454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2585454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public void getPreviewFpsRange(int[] range) { 2586454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (range == null || range.length != 2) { 2587454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li throw new IllegalArgumentException( 25885f1e69c76ef5886ed65e303490c5f660da4756efWu-cheng Li "range must be an array with two elements."); 2589454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2590454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitInt(get(KEY_PREVIEW_FPS_RANGE), range); 2591454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2592454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2593454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 2594454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * Gets the supported preview fps (frame-per-second) ranges. Each range 2595454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * contains a minimum fps and maximum fps. If minimum fps equals to 2596454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * maximum fps, the camera outputs frames in fixed frame rate. If not, 2597454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * the camera outputs frames in auto frame rate. The actual frame rate 2598454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * fluctuates between the minimum and the maximum. The values are 2599454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * multiplied by 1000 and represented in integers. For example, if frame 2600454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * rate is 26.623 frames per second, the value is 26623. 2601454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * 2602454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @return a list of supported preview fps ranges. This method returns a 2603454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * list with at least one element. Every element is an int array 2604454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * of two values - minimum fps and maximum fps. The list is 2605454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * sorted from small to large (first by maximum fps and then 2606454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * minimum fps). 2607454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MIN_INDEX 2608454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li * @see #PREVIEW_FPS_MAX_INDEX 2609454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li */ 2610454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li public List<int[]> getSupportedPreviewFpsRange() { 2611454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); 2612454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return splitRange(str); 2613454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 2614454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 2615454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li /** 26167478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * Sets the image format for preview pictures. 2617da0a56df963353a1f1bd1914fa31f870d982dd5aScott Main * <p>If this is never called, the default format will be 2618a696f5d667227365da732481770767dcb330dd23Mathias Agopian * {@link android.graphics.ImageFormat#NV21}, which 2619df4578e8ab7008a7e528d5af2ae761b33cf2bdf4Scott Main * uses the NV21 encoding format.</p> 26207478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * 2621951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of 2622951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * the available preview formats. 2623951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2624951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>It is strongly recommended that either 2625951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#NV21} or 2626951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#YV12} is used, since 2627951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * they are supported by all camera devices.</p> 2628951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2629951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <p>For YV12, the image buffer that is received is not necessarily 2630951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * tightly packed, as there may be padding at the end of each row of 2631951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * pixel data, as described in 2632951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@link android.graphics.ImageFormat#YV12}. For camera callback data, 2633951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * it can be assumed that the stride of the Y and UV data is the 2634951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * smallest possible that meets the alignment requirements. That is, if 2635951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * the preview size is <var>width x height</var>, then the following 2636951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * equations describe the buffer index for the beginning of row 2637951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>y</var> for the Y plane and row <var>c</var> for the U and V 2638951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * planes: 2639951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2640951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * {@code 2641951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <pre> 2642951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * yStride = (int) ceil(width / 16.0) * 16; 2643951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16; 2644951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * ySize = yStride * height; 2645951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uvSize = uvStride * height / 2; 2646951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * yRowIndex = yStride * y; 2647951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * uRowIndex = ySize + uvSize + uvStride * c; 2648951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * vRowIndex = ySize + uvStride * c; 2649951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * size = ySize + uvSize * 2;</pre> 2650951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * } 2651951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2652951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @param pixel_format the desired preview picture format, defined by 2653951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * one of the {@link android.graphics.ImageFormat} constants. (E.g., 2654951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>ImageFormat.NV21</var> (default), or 2655951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * <var>ImageFormat.YV12</var>) 2656951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * 2657a696f5d667227365da732481770767dcb330dd23Mathias Agopian * @see android.graphics.ImageFormat 2658951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats 26599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewFormat(int pixel_format) { 26619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String s = cameraFormatForPixelFormat(pixel_format); 26629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (s == null) { 26639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 26649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid pixel_format=" + pixel_format); 26659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PREVIEW_FORMAT, s); 26689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 26699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 26709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 26713f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * Returns the image format for preview frames got from 26729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * {@link PreviewCallback}. 26737478ea6848c0059e65a4089b4ec2ff4158520870Wu-cheng Li * 26743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return the preview format. 26753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 2676951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see #setPreviewFormat 26779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 26789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPreviewFormat() { 26799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); 26809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 26819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 26829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 2683f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} 2684f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * is always supported. {@link android.graphics.ImageFormat#YV12} 2685f9293e7d5057f54ec90423f55b78138d5729e30fWu-cheng Li * is always supported since API level 12. 26869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 26873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported preview formats. This method will always 26883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 26893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 2690951516358e2841d2425f610bcd0175d9960135d2Eino-Ville Talvala * @see #setPreviewFormat 26919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 26929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPreviewFormats() { 26939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); 2694eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang ArrayList<Integer> formats = new ArrayList<Integer>(); 2695eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang for (String s : split(str)) { 2696eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang int f = pixelFormatForCameraFormat(s); 2697a696f5d667227365da732481770767dcb330dd23Mathias Agopian if (f == ImageFormat.UNKNOWN) continue; 2698eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang formats.add(f); 2699eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang } 2700eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang return formats; 27019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 270432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Sets the dimensions for pictures.</p> 27059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 270632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Applications need to consider the display orientation. See {@link 270732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * #setPreviewSize(int,int)} for reference.</p> 2708c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 27099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width for pictures, in pixels 27109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height for pictures, in pixels 2711c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * @see #setPreviewSize(int,int) 2712c157e0cd161e5b3b28b72bafebb3360ed856a608Wu-cheng Li * 27139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPictureSize(int width, int height) { 27159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String v = Integer.toString(width) + "x" + Integer.toString(height); 27169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PICTURE_SIZE, v); 27179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 27209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the dimension setting for pictures. 27219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return a Size object with the height and width setting 27239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for pictures 27249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Size getPictureSize() { 27269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String pair = get(KEY_PICTURE_SIZE); 27279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return strToSize(pair); 27289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 27299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 27319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported picture sizes. 27329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27333f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported picture sizes. This method will always 27343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 27359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 27369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Size> getSupportedPictureSizes() { 27379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); 27389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return splitSize(str); 27399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 27429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the image format for pictures. 27439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param pixel_format the desired picture format 2745a696f5d667227365da732481770767dcb330dd23Mathias Agopian * (<var>ImageFormat.NV21</var>, 2746a696f5d667227365da732481770767dcb330dd23Mathias Agopian * <var>ImageFormat.RGB_565</var>, or 2747a696f5d667227365da732481770767dcb330dd23Mathias Agopian * <var>ImageFormat.JPEG</var>) 2748a696f5d667227365da732481770767dcb330dd23Mathias Agopian * @see android.graphics.ImageFormat 27499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPictureFormat(int pixel_format) { 27519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String s = cameraFormatForPixelFormat(pixel_format); 27529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (s == null) { 27539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 27549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid pixel_format=" + pixel_format); 27559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_PICTURE_FORMAT, s); 27589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 27619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the image format for pictures. 27629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return the picture format 27643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 27659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 27669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPictureFormat() { 27679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); 27689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 27699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 27709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 27719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported picture formats. 27729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 27733f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return supported picture formats. This method will always return a 27743f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * list with at least one element. 27753f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see android.graphics.ImageFormat 27769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 27779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<Integer> getSupportedPictureFormats() { 27789c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); 27799c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li ArrayList<Integer> formats = new ArrayList<Integer>(); 27809c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li for (String s : split(str)) { 27819c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li int f = pixelFormatForCameraFormat(s); 2782a696f5d667227365da732481770767dcb330dd23Mathias Agopian if (f == ImageFormat.UNKNOWN) continue; 27839c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li formats.add(f); 27849c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li } 27859c79938d47a3caa06e5fb956955374f30c55992bWu-cheng Li return formats; 27869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 27889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private String cameraFormatForPixelFormat(int pixel_format) { 27899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(pixel_format) { 2790a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; 2791a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; 2792a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; 279310a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; 2794a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; 2795a696f5d667227365da732481770767dcb330dd23Mathias Agopian case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; 279670fb9085044c5e6f52c33c970d238b764cf2373bWu-cheng Li case ImageFormat.BAYER_RGGB: return PIXEL_FORMAT_BAYER_RGGB; 2797a696f5d667227365da732481770767dcb330dd23Mathias Agopian default: return null; 27989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 27999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 28009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private int pixelFormatForCameraFormat(String format) { 28029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (format == null) 2803a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.UNKNOWN; 28049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV422SP)) 2806a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.NV16; 28079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV420SP)) 2809a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.NV21; 28109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2811eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang if (format.equals(PIXEL_FORMAT_YUV422I)) 2812a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.YUY2; 2813eb68c46a40c773eb56ef7bcf8e7ece5c6a5a8d23Chih-Chung Chang 281410a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li if (format.equals(PIXEL_FORMAT_YUV420P)) 281510a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li return ImageFormat.YV12; 281610a1b30dfbd0bbeae6776e353600986647c6e0a8Wu-cheng Li 28179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_RGB565)) 2818a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.RGB_565; 28199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (format.equals(PIXEL_FORMAT_JPEG)) 2821a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.JPEG; 28229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2823a696f5d667227365da732481770767dcb330dd23Mathias Agopian return ImageFormat.UNKNOWN; 28249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 28259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 28269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28278969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * Sets the clockwise rotation angle in degrees relative to the 28288969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * orientation of the camera. This affects the pictures returned from 28298969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * JPEG {@link PictureCallback}. The camera driver may set orientation 28308969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * in the EXIF header without rotating the picture. Or the driver may 28318969ea12ca55eef75783796ba52a0120f7188095Wu-cheng Li * rotate the picture and the EXIF thumbnail. If the Jpeg picture is 2832a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * rotated, the orientation in the EXIF header will be missing or 1 (row 2833a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * #0 is top and column #0 is left side). 2834a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * 2835a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * <p> 2836a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * If applications want to rotate the picture to match the orientation 2837a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * of what users see, apps should use 2838a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * {@link android.view.OrientationEventListener} and 2839a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * {@link android.hardware.Camera.CameraInfo}. The value from 2840a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * OrientationEventListener is relative to the natural orientation of 2841a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * the device. CameraInfo.orientation is the angle between camera 2842a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * orientation and natural device orientation. The sum of the two is the 2843a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * rotation angle for back-facing camera. The difference of the two is 2844a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * the rotation angle for front-facing camera. Note that the JPEG 2845a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * pictures of front-facing cameras are not mirrored as in preview 2846a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * display. 2847a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * 2848a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * <p> 2849a1b02dbb6edf0644720716d3f271b1ee091aa2d6Igor Murashkin * For example, suppose the natural orientation of the device is 28502fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * portrait. The device is rotated 270 degrees clockwise, so the device 28512fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * orientation is 270. Suppose a back-facing camera sensor is mounted in 28522fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * landscape and the top side of the camera sensor is aligned with the 28532fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * right edge of the display in natural orientation. So the camera 28542fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * orientation is 90. The rotation should be set to 0 (270 + 90). 28552fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 285669ea4e15e52c456537575d21443ac1efdb03a902Brad Fitzpatrick * <p>The reference code is as follows. 28572fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 2858e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala * <pre> 28599a10bf0386ac9822e33a15820d8cd1fd8bdb5572Scott Main * public void onOrientationChanged(int orientation) { 28602fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * if (orientation == ORIENTATION_UNKNOWN) return; 28612fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * android.hardware.Camera.CameraInfo info = 28622fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * new android.hardware.Camera.CameraInfo(); 28632fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * android.hardware.Camera.getCameraInfo(cameraId, info); 28642fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * orientation = (orientation + 45) / 90 * 90; 28652fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * int rotation = 0; 28662fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { 28672fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * rotation = (info.orientation - orientation + 360) % 360; 28682fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } else { // back-facing camera 28692fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * rotation = (info.orientation + orientation) % 360; 28702fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * } 28712fe6fcaff4bdab45484055d6c18dd96d1b7b7be1Wu-cheng Li * mParameters.setRotation(rotation); 28722fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * } 2873e0cc55ac725feec88c77b482d1990221c9a80f74Eino-Ville Talvala * </pre> 28742fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 28752fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * @param rotation The rotation angle in degrees relative to the 28762fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * orientation of the camera. Rotation can only be 0, 28772fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * 90, 180 or 270. 28789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @throws IllegalArgumentException if rotation value is invalid. 28799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @see android.view.OrientationEventListener 28802fb818ca7dd53d00646854a2473f1a69be43067cWu-cheng Li * @see #getCameraInfo(int, CameraInfo) 28819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setRotation(int rotation) { 28839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (rotation == 0 || rotation == 90 || rotation == 180 28849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li || rotation == 270) { 28859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_ROTATION, Integer.toString(rotation)); 28869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } else { 28879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li throw new IllegalArgumentException( 28889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li "Invalid rotation=" + rotation); 28899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 28919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 28929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 28939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS latitude coordinate. This will be stored in JPEG EXIF 28949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * header. 28959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 28969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param latitude GPS latitude coordinate. 28979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 28989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsLatitude(double latitude) { 28999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_LATITUDE, Double.toString(latitude)); 29009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS longitude coordinate. This will be stored in JPEG EXIF 29049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * header. 29059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param longitude GPS longitude coordinate. 29079b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29089b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsLongitude(double longitude) { 29099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_LONGITUDE, Double.toString(longitude)); 29109b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29119b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS altitude. This will be stored in JPEG EXIF header. 29149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param altitude GPS altitude in meters. 29169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsAltitude(double altitude) { 29189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_ALTITUDE, Double.toString(altitude)); 29199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets GPS timestamp. This will be stored in JPEG EXIF header. 29239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @param timestamp GPS timestamp (UTC in seconds since January 1, 29259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 1970). 29269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setGpsTimestamp(long timestamp) { 29289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); 29299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 2932e208377fbab6b90f41e68699700942a81f4caaebRay Chen * Sets GPS processing method. It will store up to 32 characters 2933055c986ab841f8f758398841730f1e90313b132aRay Chen * in JPEG EXIF header. 2934055c986ab841f8f758398841730f1e90313b132aRay Chen * 2935055c986ab841f8f758398841730f1e90313b132aRay Chen * @param processing_method The processing method to get this location. 2936055c986ab841f8f758398841730f1e90313b132aRay Chen */ 2937055c986ab841f8f758398841730f1e90313b132aRay Chen public void setGpsProcessingMethod(String processing_method) { 2938055c986ab841f8f758398841730f1e90313b132aRay Chen set(KEY_GPS_PROCESSING_METHOD, processing_method); 2939055c986ab841f8f758398841730f1e90313b132aRay Chen } 2940055c986ab841f8f758398841730f1e90313b132aRay Chen 2941055c986ab841f8f758398841730f1e90313b132aRay Chen /** 29429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Removes GPS latitude, longitude, altitude, and timestamp from the 29439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * parameters. 29449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void removeGpsData() { 29469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_LATITUDE); 29479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_LONGITUDE); 29489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_ALTITUDE); 29499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li remove(KEY_GPS_TIMESTAMP); 2950055c986ab841f8f758398841730f1e90313b132aRay Chen remove(KEY_GPS_PROCESSING_METHOD); 29519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current white balance setting. 29559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29563f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current white balance. null if white balance setting is not 29573f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 29583f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_AUTO 29593f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_INCANDESCENT 29603f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_FLUORESCENT 29613f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_WARM_FLUORESCENT 29623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_DAYLIGHT 29633f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT 29643f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_TWILIGHT 29653f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #WHITE_BALANCE_SHADE 29663f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * 29679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getWhiteBalance() { 29699b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_WHITE_BALANCE); 29709b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29719b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 297316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * Sets the white balance. Changing the setting will release the 2974b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li * auto-white balance lock. It is recommended not to change white 2975b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li * balance and AWB lock at the same time. 29769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value new white balance. 29783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getWhiteBalance() 2979037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 29809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setWhiteBalance(String value) { 2982b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li String oldValue = get(KEY_WHITE_BALANCE); 2983b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (same(value, oldValue)) return; 29849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_WHITE_BALANCE, value); 298516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); 29869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 29889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 29899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported white balance. 29909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 29913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported white balance. null if white balance 29923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * setting is not supported. 29933f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getWhiteBalance() 29949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 29959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedWhiteBalance() { 29969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); 29979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 29989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 29999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current color effect setting. 30029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30033f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current color effect. null if color effect 30049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 30053f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_NONE 30063f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_MONO 30073f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_NEGATIVE 30083f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_SOLARIZE 30093f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_SEPIA 30103f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_POSTERIZE 30113f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_WHITEBOARD 30123f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_BLACKBOARD 30133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #EFFECT_AQUA 30149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getColorEffect() { 30169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_EFFECT); 30179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the current color effect setting. 30219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30223f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value new color effect. 30233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getColorEffect() 30249b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30259b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setColorEffect(String value) { 30269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_EFFECT, value); 30279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported color effects. 30319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30323f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported color effects. null if color effect 30339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 30343f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getColorEffect() 30359b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30369b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedColorEffects() { 30379b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); 30389b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 30399b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30409b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30419b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current antibanding setting. 30449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30453f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current antibanding. null if antibanding setting is not 30463f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 30473f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_AUTO 30483f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_50HZ 30493f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_60HZ 30503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #ANTIBANDING_OFF 30519b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getAntibanding() { 30539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_ANTIBANDING); 30549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the antibanding. 30589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30593f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param antibanding new antibanding value. 30603f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getAntibanding() 30619b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30629b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setAntibanding(String antibanding) { 30639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_ANTIBANDING, antibanding); 30649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported antibanding values. 30689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30693f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported antibanding values. null if antibanding 30703f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * setting is not supported. 30713f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getAntibanding() 30729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 30739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedAntibanding() { 30749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); 30759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 30769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 30779b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 30789b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 30799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current scene mode setting. 30809b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 30819b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * @return one of SCENE_MODE_XXX string constant. null if scene mode 30829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * setting is not supported. 30833f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_AUTO 30843f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_ACTION 30853f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_PORTRAIT 30863f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_LANDSCAPE 30873f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_NIGHT 30883f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_NIGHT_PORTRAIT 30893f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_THEATRE 30903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_BEACH 30913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SNOW 30923f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SUNSET 30933f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_STEADYPHOTO 30943f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_FIREWORKS 30953f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_SPORTS 30963f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_PARTY 30973f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #SCENE_MODE_CANDLELIGHT 3098da2f0ea10822628875a956e4bf096066c0debe9fEino-Ville Talvala * @see #SCENE_MODE_BARCODE 30999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getSceneMode() { 31019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_SCENE_MODE); 31029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 3105c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * Sets the scene mode. Changing scene mode may override other 3106c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * parameters (such as flash mode, focus mode, white balance). For 3107c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * example, suppose originally flash mode is on and supported flash 3108c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * modes are on/off. In night scene mode, both flash mode and supported 3109c58b42327df5fbc826e2fcc2674ab6db0edfcd92Wu-cheng Li * flash mode may be changed to off. After setting scene mode, 31102988ab7c322aad7508df930204886f334216b65cWu-cheng Li * applications should call getParameters to know if some parameters are 31112988ab7c322aad7508df930204886f334216b65cWu-cheng Li * changed. 31129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31133f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value scene mode. 31143f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getSceneMode() 31159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setSceneMode(String value) { 31179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_SCENE_MODE, value); 31189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31219b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported scene modes. 31229b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31233f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported scene modes. null if scene mode setting 31243f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * is not supported. 31253f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getSceneMode() 31269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedSceneModes() { 31289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); 31299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 31309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31319b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31329b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31339b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the current flash mode setting. 31349b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31353f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return current flash mode. null if flash mode setting is not 31363f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * supported. 31373f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_OFF 31383f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_AUTO 31393f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_ON 31403f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_RED_EYE 31413f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FLASH_MODE_TORCH 31429b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31439b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public String getFlashMode() { 31449b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return get(KEY_FLASH_MODE); 31459b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31469b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31479b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31489b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Sets the flash mode. 31499b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31503f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value flash mode. 31513f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFlashMode() 31529b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31539b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public void setFlashMode(String value) { 31549b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li set(KEY_FLASH_MODE, value); 31559b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31569b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 31579b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li /** 31589b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * Gets the supported flash modes. 31599b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li * 31603f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported flash modes. null if flash mode setting 31613f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * is not supported. 31623f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFlashMode() 31639b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li */ 31649b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li public List<String> getSupportedFlashModes() { 31659b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); 31669b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return split(str); 31679b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 31689b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 316936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 317036322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Gets the current focus mode setting. 317136322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 3172699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * @return current focus mode. This method will always return a non-null 3173699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * value. Applications should call {@link 3174699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * #autoFocus(AutoFocusCallback)} to start the focus if focus 3175699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. 31763f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_AUTO 31773f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_INFINITY 31783f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_MACRO 31793f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #FOCUS_MODE_FIXED 3180f008f3ea82a0518375ee4ea41b32451badffbd95Wu-cheng Li * @see #FOCUS_MODE_EDOF 3181d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li * @see #FOCUS_MODE_CONTINUOUS_VIDEO 318236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 318336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public String getFocusMode() { 318436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li return get(KEY_FOCUS_MODE); 318536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 318636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 318736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 318836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Sets the focus mode. 318936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 31903f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @param value focus mode. 31913f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFocusMode() 319236322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 319336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public void setFocusMode(String value) { 319436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li set(KEY_FOCUS_MODE, value); 319536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 319636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 319736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li /** 319836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * Gets the supported focus modes. 319936322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li * 32003f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @return a list of supported focus modes. This method will always 32013f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * return a list with at least one element. 32023f4639a6611222ae1ae5493de49213250d292139Wu-cheng Li * @see #getFocusMode() 320336322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li */ 320436322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li public List<String> getSupportedFocusModes() { 320536322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); 320636322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li return split(str); 320736322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li } 320836322db5752c7ec196f59ba94abe5d5a63cc19f5Wu-cheng Li 320936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 32106c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the focal length (in millimeter) of the camera. 32116c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 32126c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return the focal length. This method will always return a valid 32136c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * value. 32146c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 32156c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getFocalLength() { 32166c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_FOCAL_LENGTH)); 32176c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 32186c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 32196c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 32206c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the horizontal angle of view in degrees. 32216c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 32226c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return horizontal angle of view. This method will always return a 32236c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * valid value. 32246c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 32256c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getHorizontalViewAngle() { 32266c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); 32276c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 32286c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 32296c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 32306c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * Gets the vertical angle of view in degrees. 32316c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * 32326c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * @return vertical angle of view. This method will always return a 32336c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li * valid value. 32346c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li */ 32356c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li public float getVerticalViewAngle() { 32366c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); 32376c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li } 32386c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li 32396c8d2760736a0753dad96b4bb8f98c7d075e6d54Wu-cheng Li /** 324024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the current exposure compensation index. 3241ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 324224b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return current exposure compensation index. The range is {@link 324324b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMinExposureCompensation} to {@link 324424b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMaxExposureCompensation}. 0 means exposure is not 324524b326a8978bf78e3e560723dde221792784325bWu-cheng Li * adjusted. 3246ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 3247ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li public int getExposureCompensation() { 324824b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_EXPOSURE_COMPENSATION, 0); 3249ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3250ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3251ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 325224b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Sets the exposure compensation index. 3253ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 32540402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li * @param value exposure compensation index. The valid value range is 32550402e7da70715c96af90aa95c16d1bedc5199645Wu-cheng Li * from {@link #getMinExposureCompensation} (inclusive) to {@link 325624b326a8978bf78e3e560723dde221792784325bWu-cheng Li * #getMaxExposureCompensation} (inclusive). 0 means exposure is 325724b326a8978bf78e3e560723dde221792784325bWu-cheng Li * not adjusted. Application should call 325824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * getMinExposureCompensation and getMaxExposureCompensation to 325924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * know if exposure compensation is supported. 3260ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 3261ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li public void setExposureCompensation(int value) { 3262ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li set(KEY_EXPOSURE_COMPENSATION, value); 3263ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3264ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3265ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 326624b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the maximum exposure compensation index. 3267ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li * 326824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return maximum exposure compensation index (>=0). If both this 326924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * method and {@link #getMinExposureCompensation} return 0, 327024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation is not supported. 327124b326a8978bf78e3e560723dde221792784325bWu-cheng Li */ 327224b326a8978bf78e3e560723dde221792784325bWu-cheng Li public int getMaxExposureCompensation() { 327324b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); 327424b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 327524b326a8978bf78e3e560723dde221792784325bWu-cheng Li 327624b326a8978bf78e3e560723dde221792784325bWu-cheng Li /** 327724b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the minimum exposure compensation index. 327824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * 327924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return minimum exposure compensation index (<=0). If both this 328024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * method and {@link #getMaxExposureCompensation} return 0, 328124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation is not supported. 3282ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li */ 328324b326a8978bf78e3e560723dde221792784325bWu-cheng Li public int getMinExposureCompensation() { 328424b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); 328524b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 328624b326a8978bf78e3e560723dde221792784325bWu-cheng Li 328724b326a8978bf78e3e560723dde221792784325bWu-cheng Li /** 328824b326a8978bf78e3e560723dde221792784325bWu-cheng Li * Gets the exposure compensation step. 328924b326a8978bf78e3e560723dde221792784325bWu-cheng Li * 329024b326a8978bf78e3e560723dde221792784325bWu-cheng Li * @return exposure compensation step. Applications can get EV by 329124b326a8978bf78e3e560723dde221792784325bWu-cheng Li * multiplying the exposure compensation index and step. Ex: if 329224b326a8978bf78e3e560723dde221792784325bWu-cheng Li * exposure compensation index is -6 and step is 0.333333333, EV 329324b326a8978bf78e3e560723dde221792784325bWu-cheng Li * is -2. 329424b326a8978bf78e3e560723dde221792784325bWu-cheng Li */ 329524b326a8978bf78e3e560723dde221792784325bWu-cheng Li public float getExposureCompensationStep() { 329624b326a8978bf78e3e560723dde221792784325bWu-cheng Li return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); 3297ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li } 3298ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li 3299ff723b6c43d5a8fd0ae0e0732f5d47012d74e01dWu-cheng Li /** 3300d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Sets the auto-exposure lock state. Applications should check 3301d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #isAutoExposureLockSupported} before using this method.</p> 33023773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 3303d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If set to true, the camera auto-exposure routine will immediately 3304d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * pause until the lock is set to false. Exposure compensation settings 3305d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * changes will still take effect while auto-exposure is locked.</p> 3306d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3307d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If auto-exposure is already locked, setting this to true again has 3308d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * no effect (the driver will not recalculate exposure values).</p> 3309d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3310d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Stopping preview with {@link #stopPreview()}, or triggering still 3311d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * image capture with {@link #takePicture(Camera.ShutterCallback, 3312b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}, will not change the 3313b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * lock.</p> 3314d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3315b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * <p>Exposure compensation, auto-exposure lock, and auto-white balance 3316b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * lock can be used to capture an exposure-bracketed burst of images, 3317b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * for example.</p> 3318d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3319d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Auto-exposure state, including the lock state, will not be 33203773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * maintained after camera {@link #release()} is called. Locking 33213773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * auto-exposure after {@link #open()} but before the first call to 33223773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #startPreview()} will not allow the auto-exposure routine to 3323d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * run at all, and may result in severely over- or under-exposed 3324d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * images.</p> 33253773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33263773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @param toggle new state of the auto-exposure lock. True means that 33273773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * auto-exposure is locked, false means that the auto-exposure 33283773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * routine is free to run normally. 33293773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 3330d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #getAutoExposureLock() 33313773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 33323773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public void setAutoExposureLock(boolean toggle) { 33333773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); 33343773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 33353773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 33363773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 33373773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * Gets the state of the auto-exposure lock. Applications should check 33383773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #isAutoExposureLockSupported} before using this method. See 33393773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #setAutoExposureLock} for details about the lock. 33403773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33413773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @return State of the auto-exposure lock. Returns true if 3342b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * auto-exposure is currently locked, and false otherwise. 33433773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33443773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @see #setAutoExposureLock(boolean) 33453773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33463773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 33473773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public boolean getAutoExposureLock() { 33483773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala String str = get(KEY_AUTO_EXPOSURE_LOCK); 33493773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala return TRUE.equals(str); 33503773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 33513773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 33523773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 33533773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * Returns true if auto-exposure locking is supported. Applications 33543773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * should call this before trying to lock auto-exposure. See 33553773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * {@link #setAutoExposureLock} for details about the lock. 33563773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33573773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @return true if auto-exposure lock is supported. 33583773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * @see #setAutoExposureLock(boolean) 33593773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala * 33603773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala */ 33613773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala public boolean isAutoExposureLockSupported() { 33623773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); 33633773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala return TRUE.equals(str); 33643773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala } 33653773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala 33663773eef4e36fa4171a84b495dca849be112df0a8Eino-Ville Talvala /** 3367d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Sets the auto-white balance lock state. Applications should check 3368d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #isAutoWhiteBalanceLockSupported} before using this 3369d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * method.</p> 3370d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3371d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If set to true, the camera auto-white balance routine will 3372d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * immediately pause until the lock is set to false.</p> 3373d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3374d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>If auto-white balance is already locked, setting this to true 3375d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * again has no effect (the driver will not recalculate white balance 3376d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * values).</p> 3377d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3378d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * <p>Stopping preview with {@link #stopPreview()}, or triggering still 3379d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * image capture with {@link #takePicture(Camera.ShutterCallback, 3380b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}, will not change the 3381b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * the lock.</p> 3382d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 338316b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * <p> Changing the white balance mode with {@link #setWhiteBalance} 338416b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * will release the auto-white balance lock if it is set.</p> 338516b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * 3386b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * <p>Exposure compensation, AE lock, and AWB lock can be used to 3387b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * capture an exposure-bracketed burst of images, for example. 3388b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * Auto-white balance state, including the lock state, will not be 3389b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * maintained after camera {@link #release()} is called. Locking 3390b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * auto-white balance after {@link #open()} but before the first call to 3391b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * {@link #startPreview()} will not allow the auto-white balance routine 3392b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * to run at all, and may result in severely incorrect color in captured 3393b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * images.</p> 3394d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3395d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @param toggle new state of the auto-white balance lock. True means 3396d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * that auto-white balance is locked, false means that the 3397d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * auto-white balance routine is free to run normally. 3398d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3399d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #getAutoWhiteBalanceLock() 340016b67137b893f32491a38ab81d49368322e1ae92Eino-Ville Talvala * @see #setWhiteBalance(String) 3401d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3402d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public void setAutoWhiteBalanceLock(boolean toggle) { 3403d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); 3404d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3405d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3406d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 3407d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * Gets the state of the auto-white balance lock. Applications should 3408d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * check {@link #isAutoWhiteBalanceLockSupported} before using this 3409d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * method. See {@link #setAutoWhiteBalanceLock} for details about the 3410d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * lock. 3411d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3412d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @return State of the auto-white balance lock. Returns true if 3413d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * auto-white balance is currently locked, and false 3414b4f95be03e018df825356fe2cd363797c66303f1Wu-cheng Li * otherwise. 3415d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3416d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 3417d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3418d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3419d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public boolean getAutoWhiteBalanceLock() { 3420d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala String str = get(KEY_AUTO_WHITEBALANCE_LOCK); 3421d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala return TRUE.equals(str); 3422d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3423d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3424d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 3425d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * Returns true if auto-white balance locking is supported. Applications 3426d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * should call this before trying to lock auto-white balance. See 3427d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * {@link #setAutoWhiteBalanceLock} for details about the lock. 3428d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3429d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @return true if auto-white balance lock is supported. 3430d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * @see #setAutoWhiteBalanceLock(boolean) 3431d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala * 3432d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala */ 3433d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala public boolean isAutoWhiteBalanceLockSupported() { 3434d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); 3435d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala return TRUE.equals(str); 3436d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala } 3437d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala 3438d9c2601afa46811bcb1345963d38010690981a01Eino-Ville Talvala /** 343936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Gets current zoom value. This also works when smooth zoom is in 34408cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * progress. Applications should check {@link #isZoomSupported} before 34418cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * using this method. 344236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 344336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return the current zoom value. The range is 0 to {@link 34448cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * #getMaxZoom}. 0 means the camera is not zoomed. 344536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 344636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public int getZoom() { 34478cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return getInt(KEY_ZOOM, 0); 344836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 344936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 345036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 34518cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Sets current zoom value. If the camera is zoomed (value > 0), the 34528cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * actual picture size may be smaller than picture size setting. 34538cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Applications can check the actual picture size after picture is 34548cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * returned from {@link PictureCallback}. The preview size remains the 34558cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * same in zoom. Applications should check {@link #isZoomSupported} 34568cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * before using this method. 345736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 345836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}. 345936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 346036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public void setZoom(int value) { 34618cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li set(KEY_ZOOM, value); 346236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 346336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 346436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 346536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Returns true if zoom is supported. Applications should call this 346636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * before using other zoom methods. 346736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 346836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return true if zoom is supported. 346936f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 347036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public boolean isZoomSupported() { 34718cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li String str = get(KEY_ZOOM_SUPPORTED); 34728cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return TRUE.equals(str); 347336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 347436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 347536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 347636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Gets the maximum zoom value allowed for snapshot. This is the maximum 347736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * value that applications can set to {@link #setZoom(int)}. 34788cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Applications should call {@link #isZoomSupported} before using this 34798cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * method. This value may change in different preview size. Applications 34808cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * should call this again after setting preview size. 348136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 348236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return the maximum zoom value supported by the camera. 348336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 348436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public int getMaxZoom() { 34858cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return getInt(KEY_MAX_ZOOM, 0); 348636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 348736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 348836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 34898cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * Gets the zoom ratios of all zoom values. Applications should check 34908cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * {@link #isZoomSupported} before using this method. 349136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 34928cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is 34938cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * returned as 320. The number of elements is {@link 34948cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * #getMaxZoom} + 1. The list is sorted from small to large. The 34958cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * first element is always 100. The last element is the zoom 34968cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li * ratio of the maximum zoom value. 349736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 34988cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li public List<Integer> getZoomRatios() { 34998cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return splitInt(get(KEY_ZOOM_RATIOS)); 350036f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 350136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 350236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li /** 350336f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * Returns true if smooth zoom is supported. Applications should call 350436f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * this before using other smooth zoom methods. 350536f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * 350636f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li * @return true if smooth zoom is supported. 350736f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li */ 350836f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li public boolean isSmoothZoomSupported() { 35098cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); 35108cbb8f5e1f939b03515cb4d5942c3fcb226efb9eWu-cheng Li return TRUE.equals(str); 351136f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li } 351236f68b8f24df906c969581b0b8e1a47f95dc03cbWu-cheng Li 3513e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li /** 351432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the distances from the camera to where an object appears to be 3515e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * in focus. The object is sharpest at the optimal focus distance. The 351632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * depth of field is the far focus distance minus near focus distance.</p> 3517e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 351832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus distances may change after calling {@link 3519e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link 3520e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * #startPreview()}. Applications can call {@link #getParameters()} 3521e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * and this method anytime to get the latest focus distances. If the 3522d45cb72ac0d7d57829ffc9223decb89a5fc42ce2Wu-cheng Li * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change 352332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * from time to time.</p> 3524699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * 352532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>This method is intended to estimate the distance between the camera 3526699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * and the subject. After autofocus, the subject distance may be within 3527699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * near and far focus distance. However, the precision depends on the 3528699fe9397974685e6b2c73f9a3a0eb9e5a5a2ccfWu-cheng Li * camera hardware, autofocus algorithm, the focus area, and the scene. 352932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * The error can be large and it should be only used as a reference.</p> 3530e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 353132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Far focus distance >= optimal focus distance >= near focus distance. 3532185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * If the focus distance is infinity, the value will be 353332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * {@code Float.POSITIVE_INFINITY}.</p> 3534e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * 3535e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * @param output focus distances in meters. output must be a float 3536e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * array with three elements. Near focus distance, optimal focus 3537e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li * distance, and far focus distance will be filled in the array. 3538185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_NEAR_INDEX 3539185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_OPTIMAL_INDEX 3540185cc455a87c636d48ad9a16c13d2ebad7433735Wu-cheng Li * @see #FOCUS_DISTANCE_FAR_INDEX 3541e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li */ 3542e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li public void getFocusDistances(float[] output) { 3543e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li if (output == null || output.length != 3) { 3544e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li throw new IllegalArgumentException( 3545f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa "output must be a float array with three elements."); 3546e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3547454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitFloat(get(KEY_FOCUS_DISTANCES), output); 3548e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3549e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 355030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 355130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Gets the maximum number of focus areas supported. This is the maximum 35527b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * length of the list in {@link #setFocusAreas(List)} and 35537b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * {@link #getFocusAreas()}. 355430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 355530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @return the maximum number of focus areas supported by the camera. 355630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @see #getFocusAreas() 355730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 355830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public int getMaxNumFocusAreas() { 355930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); 356030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 356130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 356230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 356332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the current focus areas. Camera driver uses the areas to decide 356432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * focus.</p> 356530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 356632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Before using this API or {@link #setFocusAreas(List)}, apps should 35677b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * call {@link #getMaxNumFocusAreas()} to know the maximum number of 356832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * focus areas first. If the value is 0, focus area is not supported.</p> 356930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 357032a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Each focus area is a rectangle with specified weight. The direction 357130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * is relative to the sensor orientation, that is, what the sensor sees. 357230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * The direction is not affected by the rotation or mirroring of 357330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle 357430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * range from -1000 to 1000. (-1000, -1000) is the upper left point. 3575bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * (1000, 1000) is the lower right point. The width and height of focus 357632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * areas cannot be 0 or negative.</p> 357730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 357832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The weight must range from 1 to 1000. The weight should be 35794e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * interpreted as a per-pixel weight - all pixels in the area have the 35804e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * specified weight. This means a small area with the same weight as a 35814e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * larger area will have less influence on the focusing than the larger 35824e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * area. Focus areas can partially overlap and the driver will add the 358332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * weights in the overlap region.</p> 358430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 358532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>A special case of a {@code null} focus area list means the driver is 358632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * free to select focus targets as it wants. For example, the driver may 358732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * use more signals to select focus areas and change them 358832a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * dynamically. Apps can set the focus area list to {@code null} if they 358932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * want the driver to completely control focusing.</p> 359030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 359132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus areas are relative to the current field of view 359230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) 359330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * represents the top of the currently visible camera frame. The focus 359430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * area cannot be set to be outside the current field of view, even 359532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * when using zoom.</p> 359630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 359732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Focus area only has effect if the current focus mode is 359853b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, 359953b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or 360053b30912d3e8598c05e47308981971e958e98db2Wu-cheng Li * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> 360130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 360230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @return a list of current focus areas 360330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 360430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li public List<Area> getFocusAreas() { 3605f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li return splitArea(get(KEY_FOCUS_AREAS)); 360630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 360730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 360830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li /** 360930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * Sets focus areas. See {@link #getFocusAreas()} for documentation. 361030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * 36117b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * @param focusAreas the focus areas 361230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li * @see #getFocusAreas() 361330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li */ 3614e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public void setFocusAreas(List<Area> focusAreas) { 3615e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li set(KEY_FOCUS_AREAS, focusAreas); 3616e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3617e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3618e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 3619e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * Gets the maximum number of metering areas supported. This is the 36207b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * maximum length of the list in {@link #setMeteringAreas(List)} and 36217b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * {@link #getMeteringAreas()}. 3622e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 3623e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @return the maximum number of metering areas supported by the camera. 3624e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @see #getMeteringAreas() 3625e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3626e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public int getMaxNumMeteringAreas() { 3627e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li return getInt(KEY_MAX_NUM_METERING_AREAS, 0); 3628e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3629e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3630e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 363132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Gets the current metering areas. Camera driver uses these areas to 363232a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * decide exposure.</p> 3633e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 363432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should 36357b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * call {@link #getMaxNumMeteringAreas()} to know the maximum number of 36367b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * metering areas first. If the value is 0, metering area is not 363732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * supported.</p> 3638e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 363932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Each metering area is a rectangle with specified weight. The 3640e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * direction is relative to the sensor orientation, that is, what the 3641e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * sensor sees. The direction is not affected by the rotation or 3642e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the 3643e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left 3644bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li * point. (1000, 1000) is the lower right point. The width and height of 364532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * metering areas cannot be 0 or negative.</p> 3646e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 364732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>The weight must range from 1 to 1000, and represents a weight for 36484e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * every pixel in the area. This means that a large metering area with 36494e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * the same weight as a smaller area will have more effect in the 36504e396e063c8b0fa6201b47166f547a98abfd6038Eino-Ville Talvala * metering result. Metering areas can partially overlap and the driver 365132a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * will add the weights in the overlap region.</p> 3652e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 365332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>A special case of a {@code null} metering area list means the driver 365432a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * is free to meter as it chooses. For example, the driver may use more 365532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * signals to select metering areas and change them dynamically. Apps 365632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * can set the metering area list to {@code null} if they want the 365732a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * driver to completely control metering.</p> 3658e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 365932a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>Metering areas are relative to the current field of view 3660e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) 3661e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * represents the top of the currently visible camera frame. The 3662e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * metering area cannot be set to be outside the current field of view, 366332a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * even when using zoom.</p> 3664e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 366532a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * <p>No matter what metering areas are, the final exposure are compensated 366632a972c693400db50717435139fa292a63bc937aEino-Ville Talvala * by {@link #setExposureCompensation(int)}.</p> 3667e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 3668e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @return a list of current metering areas 3669e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3670e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public List<Area> getMeteringAreas() { 3671d8aab93f96a6357dedc791ccdea92412fb423d15Wu-cheng Li return splitArea(get(KEY_METERING_AREAS)); 3672e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li } 3673e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li 3674e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li /** 3675e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * Sets metering areas. See {@link #getMeteringAreas()} for 3676e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * documentation. 3677e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * 36787b1c5c891a09e0e2a2de101fbf951cdc89e03957Wu-cheng Li * @param meteringAreas the metering areas 3679e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li * @see #getMeteringAreas() 3680e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li */ 3681e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li public void setMeteringAreas(List<Area> meteringAreas) { 3682e98e4c806320ccb3078805ac019cca3ed9796123Wu-cheng Li set(KEY_METERING_AREAS, meteringAreas); 368330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 368430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 36854c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li /** 36864c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * Gets the maximum number of detected faces supported. This is the 36874c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * maximum length of the list returned from {@link FaceDetectionListener}. 36884c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * If the return value is 0, face detection of the specified type is not 36894c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * supported. 36904c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * 36914c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li * @return the maximum number of detected face supported by the camera. 3692464cb21e2aaa448072449b82156f18bd64c0e613Joe Fernandez * @see #startFaceDetection() 36934c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li */ 3694c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li public int getMaxNumDetectedFaces() { 3695c0c683b3344c67700882f8059e7d18266366daa9Wu-cheng Li return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); 36964c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li } 36974c2292efbbfe7338138a9a0e8eefeaabdef1a0b4Wu-cheng Li 369825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li /** 36999c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * Sets recording mode hint. This tells the camera that the intent of 37009c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * the application is to record videos {@link 37019c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * android.media.MediaRecorder#start()}, not to take still pictures 37029c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, 37039c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can 37049c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * allow MediaRecorder.start() to start faster or with fewer glitches on 37059c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * output. This should be called before starting preview for the best 37069c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * result, but can be changed while the preview is active. The default 37079c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * value is false. 37089c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * 37099c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * The app can still call takePicture() when the hint is true or call 37109c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * MediaRecorder.start() when the hint is false. But the performance may 37119c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * be worse. 37129c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * 37139c53f1c33a433c1e9bd84a26d57e0e99f616fa24Wu-cheng Li * @param hint true if the apps intend to record videos using 371425d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li * {@link android.media.MediaRecorder}. 371525d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li */ 371625d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li public void setRecordingHint(boolean hint) { 371725d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); 371825d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li } 371925d8fb51dae37f1becf4fb3d32e8600c418eb6e8Wu-cheng Li 372098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li /** 37211cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Returns true if video snapshot is supported. That is, applications 372298bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * can call {@link #takePicture(Camera.ShutterCallback, 37231cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * Camera.PictureCallback, Camera.PictureCallback, 37241cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * Camera.PictureCallback)} during recording. Applications do not need 37251cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * to call {@link #startPreview()} after taking a picture. The preview 37261cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * will be still active. Other than that, taking a picture during 37271cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * recording is identical to taking a picture normally. All settings and 37281cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * methods related to takePicture work identically. Ex: 37291cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()}, 37301cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The 37311cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and 37321cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * {@link #FLASH_MODE_ON} also still work, but the video will record the 37331cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * flash.</p> 37341cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * 37351cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Applications can set shutter callback as null to avoid the shutter 373698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * sound. It is also recommended to set raw picture and post view 37371cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * callbacks to null to avoid the interrupt of preview display.</p> 373898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * 37391cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * <p>Field-of-view of the recorded video may be different from that of the 37401cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * captured pictures. The maximum size of a video snapshot may be 37411cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * smaller than that for regular still captures. If the current picture 37421cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * size is set higher than can be supported by video snapshot, the 37431cab31a45d9455a7b5a25c0deb447c455be4a178Eino-Ville Talvala * picture will be captured at the maximum supported size instead.</p> 374498bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * 374598bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li * @return true if video snapshot is supported. 374698bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li */ 374798bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li public boolean isVideoSnapshotSupported() { 374898bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); 374998bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li return TRUE.equals(str); 375098bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li } 375198bb251c8b527600e7a4cca6cc33499710bbfbf1Wu-cheng Li 3752037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3753037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Enables and disables video stabilization. Use 3754037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #isVideoStabilizationSupported} to determine if calling this 3755037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * method is valid.</p> 3756037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3757037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Video stabilization reduces the shaking due to the motion of the 3758037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * camera in both the preview stream and in recorded videos, including 3759037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * data received from the preview callback. It does not reduce motion 3760037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * blur in images captured with 3761037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link Camera#takePicture takePicture}.</p> 3762037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3763037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * <p>Video stabilization can be enabled and disabled while preview or 3764037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * recording is active, but toggling it may cause a jump in the video 3765037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * stream that may be undesirable in a recorded video.</p> 3766037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3767037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @param toggle Set to true to enable video stabilization, and false to 3768037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * disable video stabilization. 3769037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #isVideoStabilizationSupported() 3770037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #getVideoStabilization() 3771037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3772037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public void setVideoStabilization(boolean toggle) { 3773037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); 3774037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3775037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 3776037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3777037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * Get the current state of video stabilization. See 3778037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #setVideoStabilization} for details of video stabilization. 3779037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3780037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @return true if video stabilization is enabled 3781037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #isVideoStabilizationSupported() 3782037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setVideoStabilization(boolean) 3783037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3784037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public boolean getVideoStabilization() { 3785037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala String str = get(KEY_VIDEO_STABILIZATION); 3786037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala return TRUE.equals(str); 3787037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3788037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 3789037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala /** 3790037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * Returns true if video stabilization is supported. See 3791037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * {@link #setVideoStabilization} for details of video stabilization. 3792037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * 3793037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @return true if video stabilization is supported 3794037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #setVideoStabilization(boolean) 3795037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala * @see #getVideoStabilization() 3796037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala */ 3797037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala public boolean isVideoStabilizationSupported() { 3798037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); 3799037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala return TRUE.equals(str); 3800037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala } 3801037abb8bb064c2878858c9b69978f6754f242627Eino-Ville Talvala 38029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of String. 38039b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 38049b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<String> split(String str) { 38059b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38069b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38070a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38080a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 38099b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<String> substrings = new ArrayList<String>(); 38100a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38110a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen substrings.add(s); 38129b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38139b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return substrings; 38149b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38159b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38169b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of Integer. 38179b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 38189b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<Integer> splitInt(String str) { 38199b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38209b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38210a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38220a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 38239b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<Integer> substrings = new ArrayList<Integer>(); 38240a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38250a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen substrings.add(Integer.parseInt(s)); 38269b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38279b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (substrings.size() == 0) return null; 38289b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return substrings; 38299b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38309b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 3831454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private void splitInt(String str, int[] output) { 3832454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null) return; 3833454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 38340a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38350a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 3836454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int index = 0; 38370a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38380a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen output[index++] = Integer.parseInt(s); 3839454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3840454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3841454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3842e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li // Splits a comma delimited string to an ArrayList of Float. 3843454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private void splitFloat(String str, float[] output) { 3844454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null) return; 3845e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 38460a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38470a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 3848454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int index = 0; 38490a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38500a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen output[index++] = Float.parseFloat(s); 3851e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3852e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li } 3853e339c5edbebedf446581f18ad70214007309bf4bWu-cheng Li 385424b326a8978bf78e3e560723dde221792784325bWu-cheng Li // Returns the value of a float parameter. 385524b326a8978bf78e3e560723dde221792784325bWu-cheng Li private float getFloat(String key, float defaultValue) { 385624b326a8978bf78e3e560723dde221792784325bWu-cheng Li try { 385724b326a8978bf78e3e560723dde221792784325bWu-cheng Li return Float.parseFloat(mMap.get(key)); 385824b326a8978bf78e3e560723dde221792784325bWu-cheng Li } catch (NumberFormatException ex) { 385924b326a8978bf78e3e560723dde221792784325bWu-cheng Li return defaultValue; 386024b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 386124b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 386224b326a8978bf78e3e560723dde221792784325bWu-cheng Li 386324b326a8978bf78e3e560723dde221792784325bWu-cheng Li // Returns the value of a integer parameter. 386424b326a8978bf78e3e560723dde221792784325bWu-cheng Li private int getInt(String key, int defaultValue) { 386524b326a8978bf78e3e560723dde221792784325bWu-cheng Li try { 386624b326a8978bf78e3e560723dde221792784325bWu-cheng Li return Integer.parseInt(mMap.get(key)); 386724b326a8978bf78e3e560723dde221792784325bWu-cheng Li } catch (NumberFormatException ex) { 386824b326a8978bf78e3e560723dde221792784325bWu-cheng Li return defaultValue; 386924b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 387024b326a8978bf78e3e560723dde221792784325bWu-cheng Li } 387124b326a8978bf78e3e560723dde221792784325bWu-cheng Li 38729b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Splits a comma delimited string to an ArrayList of Size. 38739b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null or the size is 0. 38749b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private ArrayList<Size> splitSize(String str) { 38759b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38769b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38770a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); 38780a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen splitter.setString(str); 38799b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li ArrayList<Size> sizeList = new ArrayList<Size>(); 38800a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen for (String s : splitter) { 38810a12018e4cd6eaaeaec795f6b2af4499fe3a8bcdAli Utku Selen Size size = strToSize(s); 38829b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (size != null) sizeList.add(size); 38839b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38849b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (sizeList.size() == 0) return null; 38859b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return sizeList; 38869b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 38879b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38889b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Parses a string (ex: "480x320") to Size object. 38899b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li // Return null if the passing string is null. 38909b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li private Size strToSize(String str) { 38919b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (str == null) return null; 38929b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li 38939b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li int pos = str.indexOf('x'); 38949b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li if (pos != -1) { 38959b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String width = str.substring(0, pos); 38969b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li String height = str.substring(pos + 1); 38979b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return new Size(Integer.parseInt(width), 38989b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li Integer.parseInt(height)); 38999b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 39009b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li Log.e(TAG, "Invalid size parameter string=" + str); 39019b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li return null; 39029b6a8ab8221f2df20c32711b0f1e4f301165fac2Wu-cheng Li } 3903454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3904454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // Splits a comma delimited string to an ArrayList of int array. 3905454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // Example string: "(10000,26623),(10000,30000)". Return null if the 3906454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li // passing string is null or the size is 0. 3907454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li private ArrayList<int[]> splitRange(String str) { 3908454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (str == null || str.charAt(0) != '(' 3909454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li || str.charAt(str.length() - 1) != ')') { 3910454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li Log.e(TAG, "Invalid range list string=" + str); 3911454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return null; 3912454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 3913454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3914454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li ArrayList<int[]> rangeList = new ArrayList<int[]>(); 3915454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int endIndex, fromIndex = 1; 3916454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li do { 3917454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li int[] range = new int[2]; 3918454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li endIndex = str.indexOf("),(", fromIndex); 3919454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (endIndex == -1) endIndex = str.length() - 1; 3920454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li splitInt(str.substring(fromIndex, endIndex), range); 3921454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li rangeList.add(range); 3922454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li fromIndex = endIndex + 3; 3923454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } while (endIndex != str.length() - 1); 3924454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li 3925454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li if (rangeList.size() == 0) return null; 3926454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li return rangeList; 3927454630f23784afcf3dd6fc58becbb9fb6aa878a9Wu-cheng Li } 392830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 392930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li // Splits a comma delimited string to an ArrayList of Area objects. 393030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if 3931f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li // the passing string is null or the size is 0 or (0,0,0,0,0). 393230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li private ArrayList<Area> splitArea(String str) { 393330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (str == null || str.charAt(0) != '(' 393430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li || str.charAt(str.length() - 1) != ')') { 393530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li Log.e(TAG, "Invalid area string=" + str); 393630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return null; 393730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 393830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 393930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li ArrayList<Area> result = new ArrayList<Area>(); 394030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li int endIndex, fromIndex = 1; 394130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li int[] array = new int[5]; 394230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li do { 394330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li endIndex = str.indexOf("),(", fromIndex); 394430771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (endIndex == -1) endIndex = str.length() - 1; 394530771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li splitInt(str.substring(fromIndex, endIndex), array); 394630771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li Rect rect = new Rect(array[0], array[1], array[2], array[3]); 394730771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li result.add(new Area(rect, array[4])); 394830771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li fromIndex = endIndex + 3; 394930771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } while (endIndex != str.length() - 1); 395030771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li 395130771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li if (result.size() == 0) return null; 3952f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li 3953f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (result.size() == 1) { 3954bde61a5731cdfef76a0691f8bd53b880606f5f6eWu-cheng Li Area area = result.get(0); 3955f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li Rect rect = area.rect; 3956f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li if (rect.left == 0 && rect.top == 0 && rect.right == 0 3957f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li && rect.bottom == 0 && area.weight == 0) { 3958f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li return null; 3959f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 3960f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li } 3961f715bf95ded30821e81ba93bb48c08725e1c34aaWu-cheng Li 396230771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li return result; 396330771b773393596812b6cfd2a4ddf490c43437aaWu-cheng Li } 3964b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li 3965b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li private boolean same(String s1, String s2) { 3966b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (s1 == null && s2 == null) return true; 3967b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li if (s1 != null && s1.equals(s2)) return true; 3968b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li return false; 3969b838d8d4a26c3cfea2e2a5ce831daebbb5653ae7Wu-cheng Li } 39709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 39719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 3972