The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.hardware; |
| 18 | |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 19 | import static android.system.OsConstants.*; |
| 20 | |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 23 | import android.app.ActivityThread; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 25 | import android.graphics.ImageFormat; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 26 | import android.graphics.Point; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 28 | import android.graphics.SurfaceTexture; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 29 | import android.media.IAudioService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Handler; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 31 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.Looper; |
| 33 | import android.os.Message; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 34 | import android.os.RemoteException; |
| 35 | import android.os.ServiceManager; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 36 | import android.renderscript.Allocation; |
| 37 | import android.renderscript.Element; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 38 | import android.renderscript.RSIllegalArgumentException; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 39 | import android.renderscript.RenderScript; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 40 | import android.renderscript.Type; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 41 | import android.text.TextUtils; |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 42 | import android.util.Log; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 43 | import android.view.Surface; |
| 44 | import android.view.SurfaceHolder; |
| 45 | |
| 46 | import java.io.IOException; |
| 47 | import java.lang.ref.WeakReference; |
| 48 | import java.util.ArrayList; |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 49 | import java.util.LinkedHashMap; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 50 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 53 | * The Camera class is used to set image capture settings, start/stop preview, |
| 54 | * snap pictures, and retrieve frames for encoding for video. This class is a |
| 55 | * client for the Camera service, which manages the actual camera hardware. |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 56 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 57 | * <p>To access the device camera, you must declare the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 58 | * {@link android.Manifest.permission#CAMERA} permission in your Android |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 59 | * Manifest. Also be sure to include the |
| 60 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 61 | * manifest element to declare camera features used by your application. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 62 | * For example, if you use the camera and auto-focus feature, your Manifest |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 63 | * should include the following:</p> |
| 64 | * <pre> <uses-permission android:name="android.permission.CAMERA" /> |
| 65 | * <uses-feature android:name="android.hardware.camera" /> |
| 66 | * <uses-feature android:name="android.hardware.camera.autofocus" /></pre> |
| 67 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 68 | * <p>To take pictures with this class, use the following steps:</p> |
| 69 | * |
| 70 | * <ol> |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 71 | * <li>Obtain an instance of Camera from {@link #open(int)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 72 | * |
| 73 | * <li>Get existing (default) settings with {@link #getParameters()}. |
| 74 | * |
| 75 | * <li>If necessary, modify the returned {@link Camera.Parameters} object and call |
| 76 | * {@link #setParameters(Camera.Parameters)}. |
| 77 | * |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 78 | * <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 79 | * |
| 80 | * <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to |
| 81 | * {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera |
| 82 | * will be unable to start the preview. |
| 83 | * |
| 84 | * <li><b>Important</b>: Call {@link #startPreview()} to start updating the |
| 85 | * preview surface. Preview must be started before you can take a picture. |
| 86 | * |
| 87 | * <li>When you want, call {@link #takePicture(Camera.ShutterCallback, |
| 88 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)} to |
| 89 | * capture a photo. Wait for the callbacks to provide the actual image data. |
| 90 | * |
| 91 | * <li>After taking a picture, preview display will have stopped. To take more |
| 92 | * photos, call {@link #startPreview()} again first. |
| 93 | * |
| 94 | * <li>Call {@link #stopPreview()} to stop updating the preview surface. |
| 95 | * |
| 96 | * <li><b>Important:</b> Call {@link #release()} to release the camera for |
| 97 | * use by other applications. Applications should release the camera |
| 98 | * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()} |
| 99 | * it in {@link android.app.Activity#onResume()}). |
| 100 | * </ol> |
| 101 | * |
| 102 | * <p>To quickly switch to video recording mode, use these steps:</p> |
| 103 | * |
| 104 | * <ol> |
| 105 | * <li>Obtain and initialize a Camera and start preview as described above. |
| 106 | * |
| 107 | * <li>Call {@link #unlock()} to allow the media process to access the camera. |
| 108 | * |
| 109 | * <li>Pass the camera to {@link android.media.MediaRecorder#setCamera(Camera)}. |
| 110 | * See {@link android.media.MediaRecorder} information about video recording. |
| 111 | * |
| 112 | * <li>When finished recording, call {@link #reconnect()} to re-acquire |
| 113 | * and re-lock the camera. |
| 114 | * |
| 115 | * <li>If desired, restart preview and take more photos or videos. |
| 116 | * |
| 117 | * <li>Call {@link #stopPreview()} and {@link #release()} as described above. |
| 118 | * </ol> |
| 119 | * |
| 120 | * <p>This class is not thread-safe, and is meant for use from one event thread. |
| 121 | * Most long-running operations (preview, focus, photo capture, etc) happen |
| 122 | * asynchronously and invoke callbacks as necessary. Callbacks will be invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 123 | * on the event thread {@link #open(int)} was called from. This class's methods |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 124 | * must never be called from multiple threads at once.</p> |
| 125 | * |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 126 | * <p class="caution"><strong>Caution:</strong> Different Android-powered devices |
| 127 | * may have different hardware specifications, such as megapixel ratings and |
| 128 | * auto-focus capabilities. In order for your application to be compatible with |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 129 | * more devices, you should not make assumptions about the device camera |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 130 | * specifications.</p> |
Joe Fernandez | 6c5c3c3 | 2011-10-18 14:57:05 -0700 | [diff] [blame] | 131 | * |
| 132 | * <div class="special reference"> |
| 133 | * <h3>Developer Guides</h3> |
| 134 | * <p>For more information about using cameras, read the |
| 135 | * <a href="{@docRoot}guide/topics/media/camera.html">Camera</a> developer guide.</p> |
| 136 | * </div> |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 137 | * |
| 138 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 139 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 141 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | public class Camera { |
| 143 | private static final String TAG = "Camera"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 144 | |
Wu-cheng Li | d2c2929 | 2010-05-28 17:32:41 +0800 | [diff] [blame] | 145 | // These match the enums in frameworks/base/include/camera/Camera.h |
Benny Wong | da83f46 | 2009-08-12 12:01:27 -0500 | [diff] [blame] | 146 | private static final int CAMERA_MSG_ERROR = 0x001; |
| 147 | private static final int CAMERA_MSG_SHUTTER = 0x002; |
| 148 | private static final int CAMERA_MSG_FOCUS = 0x004; |
| 149 | private static final int CAMERA_MSG_ZOOM = 0x008; |
| 150 | private static final int CAMERA_MSG_PREVIEW_FRAME = 0x010; |
| 151 | private static final int CAMERA_MSG_VIDEO_FRAME = 0x020; |
| 152 | private static final int CAMERA_MSG_POSTVIEW_FRAME = 0x040; |
| 153 | private static final int CAMERA_MSG_RAW_IMAGE = 0x080; |
| 154 | private static final int CAMERA_MSG_COMPRESSED_IMAGE = 0x100; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 155 | private static final int CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x200; |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 156 | private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 157 | private static final int CAMERA_MSG_FOCUS_MOVE = 0x800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 159 | private long mNativeContext; // accessed by native methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | private EventHandler mEventHandler; |
| 161 | private ShutterCallback mShutterCallback; |
| 162 | private PictureCallback mRawImageCallback; |
| 163 | private PictureCallback mJpegCallback; |
| 164 | private PreviewCallback mPreviewCallback; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 165 | private boolean mUsingPreviewAllocation; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 166 | private PictureCallback mPostviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | private AutoFocusCallback mAutoFocusCallback; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 168 | private AutoFocusMoveCallback mAutoFocusMoveCallback; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 169 | private OnZoomChangeListener mZoomListener; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 170 | private FaceDetectionListener mFaceListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | private ErrorCallback mErrorCallback; |
| 172 | private boolean mOneShot; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 173 | private boolean mWithBuffer; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 174 | private boolean mFaceDetectionRunning = false; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 175 | private final Object mAutoFocusCallbackLock = new Object(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 176 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 177 | private static final int NO_ERROR = 0; |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | /** |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 180 | * Broadcast Action: A new picture is taken by the camera, and the entry of |
| 181 | * the picture has been added to the media store. |
| 182 | * {@link android.content.Intent#getData} is URI of the picture. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 183 | * |
| 184 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 185 | * applications are recommended to use |
| 186 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 187 | * instead.</p> |
| 188 | * |
| 189 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 190 | * back, but only for <em>registered</em> receivers. Apps that are actively running can |
Dianne Hackborn | c154195 | 2017-04-27 10:55:49 -0700 | [diff] [blame] | 191 | * again listen to the broadcast if they want an immediate clear signal about a picture |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 192 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 193 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 194 | */ |
| 195 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 196 | public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"; |
| 197 | |
| 198 | /** |
| 199 | * Broadcast Action: A new video is recorded by the camera, and the entry |
| 200 | * of the video has been added to the media store. |
| 201 | * {@link android.content.Intent#getData} is URI of the video. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 202 | * |
| 203 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 204 | * applications are recommended to use |
| 205 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 206 | * instead.</p> |
| 207 | * |
| 208 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 209 | * back, but only for <em>registered</em> receivers. Apps that are actively running can |
Dianne Hackborn | c154195 | 2017-04-27 10:55:49 -0700 | [diff] [blame] | 210 | * again listen to the broadcast if they want an immediate clear signal about a video |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 211 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 212 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 213 | */ |
| 214 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 215 | public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"; |
| 216 | |
| 217 | /** |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 218 | * Camera HAL device API version 1.0 |
| 219 | * @hide |
| 220 | */ |
| 221 | public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100; |
| 222 | |
| 223 | /** |
| 224 | * A constant meaning the normal camera connect/open will be used. |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 225 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 226 | private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2; |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Used to indicate HAL version un-specified. |
| 230 | */ |
| 231 | private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 232 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 233 | /** |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 234 | * Hardware face detection. It does not use much CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 235 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 236 | private static final int CAMERA_FACE_DETECTION_HW = 0; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 237 | |
| 238 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 239 | * Software face detection. It uses some CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 240 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 241 | private static final int CAMERA_FACE_DETECTION_SW = 1; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 242 | |
| 243 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 244 | * Returns the number of physical cameras available on this device. |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame^] | 245 | * The return value of this method might change dynamically if the device |
| 246 | * supports external cameras and an external camera is connected or |
| 247 | * disconnected. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 248 | * |
| 249 | * @return total number of accessible camera devices, or 0 if there are no |
| 250 | * cameras or an error was encountered enumerating them. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | */ |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 252 | public native static int getNumberOfCameras(); |
| 253 | |
| 254 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 255 | * Returns the information about a particular camera. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 256 | * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 257 | * |
| 258 | * @throws RuntimeException if an invalid ID is provided, or if there is an |
| 259 | * error retrieving the information (generally due to a hardware or other |
| 260 | * low-level failure). |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 261 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 262 | public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) { |
| 263 | _getCameraInfo(cameraId, cameraInfo); |
| 264 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 265 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 266 | try { |
| 267 | if (audioService.isCameraSoundForced()) { |
| 268 | // Only set this when sound is forced; otherwise let native code |
| 269 | // decide. |
| 270 | cameraInfo.canDisableShutterSound = false; |
| 271 | } |
| 272 | } catch (RemoteException e) { |
| 273 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 274 | } |
| 275 | } |
| 276 | private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo); |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Information about a camera |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 280 | * |
| 281 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 282 | * applications. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 283 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 284 | @Deprecated |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 285 | public static class CameraInfo { |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 286 | /** |
| 287 | * The facing of the camera is opposite to that of the screen. |
| 288 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 289 | public static final int CAMERA_FACING_BACK = 0; |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * The facing of the camera is the same as that of the screen. |
| 293 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 294 | public static final int CAMERA_FACING_FRONT = 1; |
| 295 | |
| 296 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 297 | * The direction that the camera faces. It should be |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 298 | * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. |
| 299 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 300 | public int facing; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 301 | |
| 302 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 303 | * <p>The orientation of the camera image. The value is the angle that the |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 304 | * camera image needs to be rotated clockwise so it shows correctly on |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 305 | * the display in its natural orientation. It should be 0, 90, 180, or 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 306 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 307 | * <p>For example, suppose a device has a naturally tall screen. The |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 308 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 309 | * the screen. If the top side of the camera sensor is aligned with the |
| 310 | * right edge of the screen in natural orientation, the value should be |
| 311 | * 90. If the top side of a front-facing camera sensor is aligned with |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 312 | * the right of the screen, the value should be 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 313 | * |
| 314 | * @see #setDisplayOrientation(int) |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 315 | * @see Parameters#setRotation(int) |
| 316 | * @see Parameters#setPreviewSize(int, int) |
| 317 | * @see Parameters#setPictureSize(int, int) |
| 318 | * @see Parameters#setJpegThumbnailSize(int, int) |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 319 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 320 | public int orientation; |
Eino-Ville Talvala | f7c6c5a | 2012-09-19 11:46:11 -0700 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * <p>Whether the shutter sound can be disabled.</p> |
| 324 | * |
| 325 | * <p>On some devices, the camera shutter sound cannot be turned off |
| 326 | * through {@link #enableShutterSound enableShutterSound}. This field |
| 327 | * can be used to determine whether a call to disable the shutter sound |
| 328 | * will succeed.</p> |
| 329 | * |
| 330 | * <p>If this field is set to true, then a call of |
| 331 | * {@code enableShutterSound(false)} will be successful. If set to |
| 332 | * false, then that call will fail, and the shutter sound will be played |
| 333 | * when {@link Camera#takePicture takePicture} is called.</p> |
| 334 | */ |
| 335 | public boolean canDisableShutterSound; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | /** |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 339 | * Creates a new Camera object to access a particular hardware camera. If |
| 340 | * the same camera is opened by other applications, this will throw a |
| 341 | * RuntimeException. |
| 342 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 343 | * <p>You must call {@link #release()} when you are done using the camera, |
| 344 | * otherwise it will remain locked and be unavailable to other applications. |
| 345 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 346 | * <p>Your application should only have one Camera object active at a time |
| 347 | * for a particular hardware camera. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 348 | * |
| 349 | * <p>Callbacks from other methods are delivered to the event loop of the |
| 350 | * thread which called open(). If this thread has no event loop, then |
| 351 | * callbacks are delivered to the main application event loop. If there |
| 352 | * is no main application event loop, callbacks are not delivered. |
| 353 | * |
| 354 | * <p class="caution"><b>Caution:</b> On some devices, this method may |
| 355 | * take a long time to complete. It is best to call this method from a |
| 356 | * worker thread (possibly using {@link android.os.AsyncTask}) to avoid |
| 357 | * blocking the main application UI thread. |
| 358 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 359 | * @param cameraId the hardware camera to access, between 0 and |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 360 | * {@link #getNumberOfCameras()}-1. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 361 | * @return a new Camera object, connected, locked and ready for use. |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 362 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 363 | * camera is in use by another process or device policy manager has |
| 364 | * disabled the camera). |
Wu-cheng Li | facc8ce | 2011-06-17 13:09:40 +0800 | [diff] [blame] | 365 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 366 | */ |
| 367 | public static Camera open(int cameraId) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 368 | return new Camera(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 371 | /** |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 372 | * Creates a new Camera object to access the first back-facing camera on the |
| 373 | * device. If the device does not have a back-facing camera, this returns |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 374 | * null. Otherwise acts like the {@link #open(int)} call. |
| 375 | * |
| 376 | * @return a new Camera object for the first back-facing camera, or null if there is no |
| 377 | * backfacing camera |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 378 | * @see #open(int) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 379 | */ |
| 380 | public static Camera open() { |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 381 | int numberOfCameras = getNumberOfCameras(); |
| 382 | CameraInfo cameraInfo = new CameraInfo(); |
| 383 | for (int i = 0; i < numberOfCameras; i++) { |
| 384 | getCameraInfo(i, cameraInfo); |
| 385 | if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 386 | return new Camera(i); |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | return null; |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 390 | } |
| 391 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 392 | /** |
| 393 | * Creates a new Camera object to access a particular hardware camera with |
| 394 | * given hal API version. If the same camera is opened by other applications |
| 395 | * or the hal API version is not supported by this device, this will throw a |
| 396 | * RuntimeException. |
| 397 | * <p> |
| 398 | * You must call {@link #release()} when you are done using the camera, |
| 399 | * otherwise it will remain locked and be unavailable to other applications. |
| 400 | * <p> |
| 401 | * Your application should only have one Camera object active at a time for |
| 402 | * a particular hardware camera. |
| 403 | * <p> |
| 404 | * Callbacks from other methods are delivered to the event loop of the |
| 405 | * thread which called open(). If this thread has no event loop, then |
| 406 | * callbacks are delivered to the main application event loop. If there is |
| 407 | * no main application event loop, callbacks are not delivered. |
| 408 | * <p class="caution"> |
| 409 | * <b>Caution:</b> On some devices, this method may take a long time to |
| 410 | * complete. It is best to call this method from a worker thread (possibly |
| 411 | * using {@link android.os.AsyncTask}) to avoid blocking the main |
| 412 | * application UI thread. |
| 413 | * |
| 414 | * @param cameraId The hardware camera to access, between 0 and |
| 415 | * {@link #getNumberOfCameras()}-1. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 416 | * @param halVersion The HAL API version this camera device to be opened as. |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 417 | * @return a new Camera object, connected, locked and ready for use. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 418 | * |
| 419 | * @throws IllegalArgumentException if the {@code halVersion} is invalid |
| 420 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 421 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 422 | * camera is in use by another process or device policy manager has disabled |
| 423 | * the camera). |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 424 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 425 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 426 | * @see #CAMERA_HAL_API_VERSION_1_0 |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 427 | * |
| 428 | * @hide |
| 429 | */ |
| 430 | public static Camera openLegacy(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 431 | if (halVersion < CAMERA_HAL_API_VERSION_1_0) { |
| 432 | throw new IllegalArgumentException("Invalid HAL version " + halVersion); |
| 433 | } |
| 434 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 435 | return new Camera(cameraId, halVersion); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Create a legacy camera object. |
| 440 | * |
| 441 | * @param cameraId The hardware camera to access, between 0 and |
| 442 | * {@link #getNumberOfCameras()}-1. |
| 443 | * @param halVersion The HAL API version this camera device to be opened as. |
| 444 | */ |
| 445 | private Camera(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 446 | int err = cameraInitVersion(cameraId, halVersion); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 447 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 448 | if (err == -EACCES) { |
| 449 | throw new RuntimeException("Fail to connect to camera service"); |
| 450 | } else if (err == -ENODEV) { |
| 451 | throw new RuntimeException("Camera initialization failed"); |
| 452 | } else if (err == -ENOSYS) { |
| 453 | throw new RuntimeException("Camera initialization failed because some methods" |
| 454 | + " are not implemented"); |
| 455 | } else if (err == -EOPNOTSUPP) { |
| 456 | throw new RuntimeException("Camera initialization failed because the hal" |
| 457 | + " version is not supported by this device"); |
| 458 | } else if (err == -EINVAL) { |
| 459 | throw new RuntimeException("Camera initialization failed because the input" |
| 460 | + " arugments are invalid"); |
| 461 | } else if (err == -EBUSY) { |
| 462 | throw new RuntimeException("Camera initialization failed because the camera" |
| 463 | + " device was already opened"); |
| 464 | } else if (err == -EUSERS) { |
| 465 | throw new RuntimeException("Camera initialization failed because the max" |
| 466 | + " number of camera devices were already opened"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 467 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 468 | // Should never hit this. |
| 469 | throw new RuntimeException("Unknown camera error"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 473 | private int cameraInitVersion(int cameraId, int halVersion) { |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 474 | mShutterCallback = null; |
| 475 | mRawImageCallback = null; |
| 476 | mJpegCallback = null; |
| 477 | mPreviewCallback = null; |
| 478 | mPostviewCallback = null; |
| 479 | mUsingPreviewAllocation = false; |
| 480 | mZoomListener = null; |
| 481 | |
| 482 | Looper looper; |
| 483 | if ((looper = Looper.myLooper()) != null) { |
| 484 | mEventHandler = new EventHandler(this, looper); |
| 485 | } else if ((looper = Looper.getMainLooper()) != null) { |
| 486 | mEventHandler = new EventHandler(this, looper); |
| 487 | } else { |
| 488 | mEventHandler = null; |
| 489 | } |
| 490 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 491 | return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, |
| 492 | ActivityThread.currentOpPackageName()); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 495 | private int cameraInitNormal(int cameraId) { |
| 496 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT); |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Connect to the camera service using #connectLegacy |
| 501 | * |
| 502 | * <p> |
| 503 | * This acts the same as normal except that it will return |
| 504 | * the detailed error code if open fails instead of |
| 505 | * converting everything into {@code NO_INIT}.</p> |
| 506 | * |
| 507 | * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p> |
| 508 | * |
| 509 | * @return a detailed errno error code, or {@code NO_ERROR} on success |
| 510 | * |
| 511 | * @hide |
| 512 | */ |
| 513 | public int cameraInitUnspecified(int cameraId) { |
| 514 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED); |
| 515 | } |
| 516 | |
| 517 | /** used by Camera#open, Camera#open(int) */ |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 518 | Camera(int cameraId) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 519 | int err = cameraInitNormal(cameraId); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 520 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 521 | if (err == -EACCES) { |
| 522 | throw new RuntimeException("Fail to connect to camera service"); |
| 523 | } else if (err == -ENODEV) { |
| 524 | throw new RuntimeException("Camera initialization failed"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 525 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 526 | // Should never hit this. |
| 527 | throw new RuntimeException("Unknown camera error"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 531 | |
| 532 | /** |
| 533 | * @hide |
| 534 | */ |
| 535 | public static boolean checkInitErrors(int err) { |
| 536 | return err != NO_ERROR; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * @hide |
| 541 | */ |
| 542 | public static Camera openUninitialized() { |
| 543 | return new Camera(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 545 | |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 546 | /** |
| 547 | * An empty Camera for testing purpose. |
| 548 | */ |
| 549 | Camera() { |
| 550 | } |
| 551 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 552 | @Override |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 553 | protected void finalize() { |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 554 | release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 556 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 557 | private native final int native_setup(Object camera_this, int cameraId, int halVersion, |
Eino-Ville Talvala | 788717c | 2013-02-15 18:30:15 -0800 | [diff] [blame] | 558 | String packageName); |
| 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | private native final void native_release(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | |
| 563 | /** |
| 564 | * Disconnects and releases the Camera object resources. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 565 | * |
| 566 | * <p>You must call this as soon as you're done with the Camera object.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 568 | public final void release() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | native_release(); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 570 | mFaceDetectionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 574 | * Unlocks the camera to allow another process to access it. |
| 575 | * Normally, the camera is locked to the process with an active Camera |
| 576 | * object until {@link #release()} is called. To allow rapid handoff |
| 577 | * between processes, you can call this method to release the camera |
| 578 | * temporarily for another process to use; once the other process is done |
| 579 | * you can call {@link #reconnect()} to reclaim the camera. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 581 | * <p>This must be done before calling |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 582 | * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be |
| 583 | * called after recording starts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 585 | * <p>If you are not recording video, you probably do not need this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 587 | * @throws RuntimeException if the camera cannot be unlocked. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 589 | public native final void unlock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 592 | * Re-locks the camera to prevent other processes from accessing it. |
| 593 | * Camera objects are locked by default unless {@link #unlock()} is |
| 594 | * called. Normally {@link #reconnect()} is used instead. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 595 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 596 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 597 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 598 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 599 | * after recording starts or stops. |
| 600 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 601 | * <p>If you are not recording video, you probably do not need this method. |
| 602 | * |
| 603 | * @throws RuntimeException if the camera cannot be re-locked (for |
| 604 | * example, if the camera is still in use by another process). |
| 605 | */ |
| 606 | public native final void lock(); |
| 607 | |
| 608 | /** |
| 609 | * Reconnects to the camera service after another process used it. |
| 610 | * After {@link #unlock()} is called, another process may use the |
| 611 | * camera; when the process is done, you must reconnect to the camera, |
| 612 | * which will re-acquire the lock and allow you to continue using the |
| 613 | * camera. |
| 614 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 615 | * <p>Since API level 14, camera is automatically locked for applications in |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 616 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 617 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 618 | * after recording starts or stops. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 619 | * |
| 620 | * <p>If you are not recording video, you probably do not need this method. |
| 621 | * |
| 622 | * @throws IOException if a connection cannot be re-established (for |
| 623 | * example, if the camera is still in use by another process). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 624 | * @throws RuntimeException if release() has been called on this Camera |
| 625 | * instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 626 | */ |
| 627 | public native final void reconnect() throws IOException; |
| 628 | |
| 629 | /** |
| 630 | * Sets the {@link Surface} to be used for live preview. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 631 | * Either a surface or surface texture is necessary for preview, and |
| 632 | * preview is necessary to take pictures. The same surface can be re-set |
| 633 | * without harm. Setting a preview surface will un-set any preview surface |
| 634 | * texture that was set via {@link #setPreviewTexture}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 635 | * |
| 636 | * <p>The {@link SurfaceHolder} must already contain a surface when this |
| 637 | * method is called. If you are using {@link android.view.SurfaceView}, |
| 638 | * you will need to register a {@link SurfaceHolder.Callback} with |
| 639 | * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for |
| 640 | * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before |
| 641 | * calling setPreviewDisplay() or starting preview. |
| 642 | * |
| 643 | * <p>This method must be called before {@link #startPreview()}. The |
| 644 | * one exception is that if the preview surface is not set (or set to null) |
| 645 | * before startPreview() is called, then this method may be called once |
| 646 | * with a non-null parameter to set the preview surface. (This allows |
| 647 | * camera setup and surface creation to happen in parallel, saving time.) |
| 648 | * The preview surface may not otherwise change while preview is running. |
| 649 | * |
| 650 | * @param holder containing the Surface on which to place the preview, |
| 651 | * or null to remove the preview surface |
| 652 | * @throws IOException if the method fails (for example, if the surface |
| 653 | * is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 654 | * @throws RuntimeException if release() has been called on this Camera |
| 655 | * instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | */ |
| 657 | public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 658 | if (holder != null) { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 659 | setPreviewSurface(holder.getSurface()); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 660 | } else { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 661 | setPreviewSurface((Surface)null); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 665 | /** |
| 666 | * @hide |
| 667 | */ |
| 668 | public native final void setPreviewSurface(Surface surface) throws IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | |
| 670 | /** |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 671 | * Sets the {@link SurfaceTexture} to be used for live preview. |
| 672 | * Either a surface or surface texture is necessary for preview, and |
| 673 | * preview is necessary to take pictures. The same surface texture can be |
| 674 | * re-set without harm. Setting a preview surface texture will un-set any |
| 675 | * preview surface that was set via {@link #setPreviewDisplay}. |
| 676 | * |
| 677 | * <p>This method must be called before {@link #startPreview()}. The |
| 678 | * one exception is that if the preview surface texture is not set (or set |
| 679 | * to null) before startPreview() is called, then this method may be called |
| 680 | * once with a non-null parameter to set the preview surface. (This allows |
| 681 | * camera setup and surface creation to happen in parallel, saving time.) |
| 682 | * The preview surface texture may not otherwise change while preview is |
| 683 | * running. |
| 684 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 685 | * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a |
Eino-Ville Talvala | e309a0f | 2011-03-21 11:04:34 -0700 | [diff] [blame] | 686 | * SurfaceTexture set as the preview texture have an unspecified zero point, |
| 687 | * and cannot be directly compared between different cameras or different |
| 688 | * instances of the same camera, or across multiple runs of the same |
| 689 | * program. |
| 690 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 691 | * <p>If you are using the preview data to create video or still images, |
| 692 | * strongly consider using {@link android.media.MediaActionSound} to |
| 693 | * properly indicate image capture or recording start/stop to the user.</p> |
| 694 | * |
| 695 | * @see android.media.MediaActionSound |
| 696 | * @see android.graphics.SurfaceTexture |
| 697 | * @see android.view.TextureView |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 698 | * @param surfaceTexture the {@link SurfaceTexture} to which the preview |
| 699 | * images are to be sent or null to remove the current preview surface |
| 700 | * texture |
| 701 | * @throws IOException if the method fails (for example, if the surface |
| 702 | * texture is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 703 | * @throws RuntimeException if release() has been called on this Camera |
| 704 | * instance. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 705 | */ |
Glenn Kasten | dbc289d | 2011-02-09 10:15:44 -0800 | [diff] [blame] | 706 | public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 707 | |
| 708 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 709 | * Callback interface used to deliver copies of preview frames as |
| 710 | * they are displayed. |
| 711 | * |
| 712 | * @see #setPreviewCallback(Camera.PreviewCallback) |
| 713 | * @see #setOneShotPreviewCallback(Camera.PreviewCallback) |
| 714 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 715 | * @see #startPreview() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 716 | * |
| 717 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 718 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 720 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | public interface PreviewCallback |
| 722 | { |
| 723 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 724 | * Called as preview frames are displayed. This callback is invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 725 | * on the event thread {@link #open(int)} was called from. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 727 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, |
| 728 | * refer to the equations in {@link Camera.Parameters#setPreviewFormat} |
| 729 | * for the arrangement of the pixel data in the preview callback |
| 730 | * buffers. |
| 731 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 732 | * @param data the contents of the preview frame in the format defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 733 | * by {@link android.graphics.ImageFormat}, which can be queried |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 734 | * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 735 | * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 736 | * is never called, the default will be the YCbCr_420_SP |
| 737 | * (NV21) format. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 738 | * @param camera the Camera service object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | */ |
| 740 | void onPreviewFrame(byte[] data, Camera camera); |
| 741 | }; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 744 | * Starts capturing and drawing preview frames to the screen. |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 745 | * Preview will not actually start until a surface is supplied |
| 746 | * with {@link #setPreviewDisplay(SurfaceHolder)} or |
| 747 | * {@link #setPreviewTexture(SurfaceTexture)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 748 | * |
| 749 | * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)}, |
| 750 | * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or |
| 751 | * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were |
| 752 | * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)} |
| 753 | * will be called when preview data becomes available. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 754 | * |
| 755 | * @throws RuntimeException if starting preview fails; usually this would be |
| 756 | * because of a hardware or other low-level error, or because release() |
| 757 | * has been called on this Camera instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | */ |
| 759 | public native final void startPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 762 | * Stops capturing and drawing preview frames to the surface, and |
| 763 | * resets the camera for a future call to {@link #startPreview()}. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 764 | * |
| 765 | * @throws RuntimeException if stopping preview fails; usually this would be |
| 766 | * because of a hardware or other low-level error, or because release() |
| 767 | * has been called on this Camera instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | */ |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 769 | public final void stopPreview() { |
| 770 | _stopPreview(); |
| 771 | mFaceDetectionRunning = false; |
Chih-yu Huang | 664d72e | 2011-09-23 18:59:38 +0800 | [diff] [blame] | 772 | |
| 773 | mShutterCallback = null; |
| 774 | mRawImageCallback = null; |
| 775 | mPostviewCallback = null; |
| 776 | mJpegCallback = null; |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 777 | synchronized (mAutoFocusCallbackLock) { |
| 778 | mAutoFocusCallback = null; |
| 779 | } |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 780 | mAutoFocusMoveCallback = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | private native final void _stopPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | /** |
| 786 | * Return current preview state. |
| 787 | * |
| 788 | * FIXME: Unhide before release |
| 789 | * @hide |
| 790 | */ |
| 791 | public native final boolean previewEnabled(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 794 | * <p>Installs a callback to be invoked for every preview frame in addition |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 795 | * to displaying them on the screen. The callback will be repeatedly called |
| 796 | * for as long as preview is active. This method can be called at any time, |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 797 | * even while preview is live. Any other preview callbacks are |
| 798 | * overridden.</p> |
| 799 | * |
| 800 | * <p>If you are using the preview data to create video or still images, |
| 801 | * strongly consider using {@link android.media.MediaActionSound} to |
| 802 | * properly indicate image capture or recording start/stop to the user.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 804 | * @param cb a callback object that receives a copy of each preview frame, |
| 805 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 806 | * @throws RuntimeException if release() has been called on this Camera |
| 807 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 808 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | */ |
| 810 | public final void setPreviewCallback(PreviewCallback cb) { |
| 811 | mPreviewCallback = cb; |
| 812 | mOneShot = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 813 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 814 | if (cb != null) { |
| 815 | mUsingPreviewAllocation = false; |
| 816 | } |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 817 | // Always use one-shot mode. We fake camera preview mode by |
| 818 | // doing one-shot preview continuously. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 819 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 823 | * <p>Installs a callback to be invoked for the next preview frame in |
| 824 | * addition to displaying it on the screen. After one invocation, the |
| 825 | * callback is cleared. This method can be called any time, even when |
| 826 | * preview is live. Any other preview callbacks are overridden.</p> |
| 827 | * |
| 828 | * <p>If you are using the preview data to create video or still images, |
| 829 | * strongly consider using {@link android.media.MediaActionSound} to |
| 830 | * properly indicate image capture or recording start/stop to the user.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 832 | * @param cb a callback object that receives a copy of the next preview frame, |
| 833 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 834 | * @throws RuntimeException if release() has been called on this Camera |
| 835 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 836 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | */ |
| 838 | public final void setOneShotPreviewCallback(PreviewCallback cb) { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 839 | mPreviewCallback = cb; |
| 840 | mOneShot = true; |
| 841 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 842 | if (cb != null) { |
| 843 | mUsingPreviewAllocation = false; |
| 844 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 845 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 848 | private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); |
| 849 | |
| 850 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 851 | * <p>Installs a callback to be invoked for every preview frame, using |
| 852 | * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 853 | * displaying them on the screen. The callback will be repeatedly called |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 854 | * for as long as preview is active and buffers are available. Any other |
| 855 | * preview callbacks are overridden.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 856 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 857 | * <p>The purpose of this method is to improve preview efficiency and frame |
| 858 | * rate by allowing preview frame memory reuse. You must call |
| 859 | * {@link #addCallbackBuffer(byte[])} at some point -- before or after |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 860 | * calling this method -- or no callbacks will received.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 861 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 862 | * <p>The buffer queue will be cleared if this method is called with a null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 863 | * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called, |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 864 | * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is |
| 865 | * called.</p> |
| 866 | * |
| 867 | * <p>If you are using the preview data to create video or still images, |
| 868 | * strongly consider using {@link android.media.MediaActionSound} to |
| 869 | * properly indicate image capture or recording start/stop to the user.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 870 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 871 | * @param cb a callback object that receives a copy of the preview frame, |
| 872 | * or null to stop receiving callbacks and clear the buffer queue. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 873 | * @throws RuntimeException if release() has been called on this Camera |
| 874 | * instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 875 | * @see #addCallbackBuffer(byte[]) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 876 | * @see android.media.MediaActionSound |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 877 | */ |
| 878 | public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { |
| 879 | mPreviewCallback = cb; |
| 880 | mOneShot = false; |
| 881 | mWithBuffer = true; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 882 | if (cb != null) { |
| 883 | mUsingPreviewAllocation = false; |
| 884 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 885 | setHasPreviewCallback(cb != null, true); |
| 886 | } |
| 887 | |
| 888 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 889 | * Adds a pre-allocated buffer to the preview callback buffer queue. |
| 890 | * Applications can add one or more buffers to the queue. When a preview |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 891 | * frame arrives and there is still at least one available buffer, the |
| 892 | * buffer will be used and removed from the queue. Then preview callback is |
| 893 | * invoked with the buffer. If a frame arrives and there is no buffer left, |
| 894 | * the frame is discarded. Applications should add buffers back when they |
| 895 | * finish processing the data in them. |
Wu-cheng Li | c10275a | 2010-03-09 13:49:21 -0800 | [diff] [blame] | 896 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 897 | * <p>For formats besides YV12, the size of the buffer is determined by |
| 898 | * multiplying the preview image width, height, and bytes per pixel. The |
| 899 | * width and height can be read from |
| 900 | * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be |
| 901 | * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / |
| 902 | * 8, using the image format from |
| 903 | * {@link Camera.Parameters#getPreviewFormat()}. |
| 904 | * |
| 905 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the |
| 906 | * size can be calculated using the equations listed in |
| 907 | * {@link Camera.Parameters#setPreviewFormat}. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 908 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 909 | * <p>This method is only necessary when |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 910 | * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 911 | * {@link #setPreviewCallback(PreviewCallback)} or |
| 912 | * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 913 | * are automatically allocated. When a supplied buffer is too small to |
| 914 | * hold the preview frame data, preview callback will return null and |
| 915 | * the buffer will be removed from the buffer queue. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 916 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 917 | * @param callbackBuffer the buffer to add to the queue. The size of the |
| 918 | * buffer must match the values described above. |
Wu-cheng Li | 5b9bcda | 2010-03-07 14:59:28 -0800 | [diff] [blame] | 919 | * @see #setPreviewCallbackWithBuffer(PreviewCallback) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 920 | */ |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 921 | public final void addCallbackBuffer(byte[] callbackBuffer) |
| 922 | { |
| 923 | _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME); |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * Adds a pre-allocated buffer to the raw image callback buffer queue. |
| 928 | * Applications can add one or more buffers to the queue. When a raw image |
| 929 | * frame arrives and there is still at least one available buffer, the |
| 930 | * buffer will be used to hold the raw image data and removed from the |
| 931 | * queue. Then raw image callback is invoked with the buffer. If a raw |
| 932 | * image frame arrives but there is no buffer left, the frame is |
| 933 | * discarded. Applications should add buffers back when they finish |
| 934 | * processing the data in them by calling this method again in order |
| 935 | * to avoid running out of raw image callback buffers. |
| 936 | * |
| 937 | * <p>The size of the buffer is determined by multiplying the raw image |
| 938 | * width, height, and bytes per pixel. The width and height can be |
| 939 | * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel |
| 940 | * can be computed from |
| 941 | * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, |
| 942 | * using the image format from {@link Camera.Parameters#getPreviewFormat()}. |
| 943 | * |
| 944 | * <p>This method is only necessary when the PictureCallbck for raw image |
| 945 | * is used while calling {@link #takePicture(Camera.ShutterCallback, |
| 946 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 947 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 948 | * <p>Please note that by calling this method, the mode for |
| 949 | * application-managed callback buffers is triggered. If this method has |
| 950 | * never been called, null will be returned by the raw image callback since |
| 951 | * there is no image callback buffer available. Furthermore, When a supplied |
| 952 | * buffer is too small to hold the raw image data, raw image callback will |
| 953 | * return null and the buffer will be removed from the buffer queue. |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 954 | * |
| 955 | * @param callbackBuffer the buffer to add to the raw image callback buffer |
| 956 | * queue. The size should be width * height * (bits per pixel) / 8. An |
| 957 | * null callbackBuffer will be ignored and won't be added to the queue. |
| 958 | * |
| 959 | * @see #takePicture(Camera.ShutterCallback, |
| 960 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 961 | * |
| 962 | * {@hide} |
| 963 | */ |
| 964 | public final void addRawImageCallbackBuffer(byte[] callbackBuffer) |
| 965 | { |
| 966 | addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE); |
| 967 | } |
| 968 | |
| 969 | private final void addCallbackBuffer(byte[] callbackBuffer, int msgType) |
| 970 | { |
| 971 | // CAMERA_MSG_VIDEO_FRAME may be allowed in the future. |
| 972 | if (msgType != CAMERA_MSG_PREVIEW_FRAME && |
| 973 | msgType != CAMERA_MSG_RAW_IMAGE) { |
| 974 | throw new IllegalArgumentException( |
| 975 | "Unsupported message type: " + msgType); |
| 976 | } |
| 977 | |
| 978 | _addCallbackBuffer(callbackBuffer, msgType); |
| 979 | } |
| 980 | |
| 981 | private native final void _addCallbackBuffer( |
| 982 | byte[] callbackBuffer, int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 984 | /** |
| 985 | * <p>Create a {@link android.renderscript RenderScript} |
| 986 | * {@link android.renderscript.Allocation Allocation} to use as a |
| 987 | * destination of preview callback frames. Use |
| 988 | * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use |
| 989 | * the created Allocation as a destination for camera preview frames.</p> |
| 990 | * |
| 991 | * <p>The Allocation will be created with a YUV type, and its contents must |
| 992 | * be accessed within Renderscript with the {@code rsGetElementAtYuv_*} |
| 993 | * accessor methods. Its size will be based on the current |
| 994 | * {@link Parameters#getPreviewSize preview size} configured for this |
| 995 | * camera.</p> |
| 996 | * |
| 997 | * @param rs the RenderScript context for this Allocation. |
| 998 | * @param usage additional usage flags to set for the Allocation. The usage |
| 999 | * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always |
| 1000 | * be set on the created Allocation, but additional flags may be provided |
| 1001 | * here. |
| 1002 | * @return a new YUV-type Allocation with dimensions equal to the current |
| 1003 | * preview size. |
| 1004 | * @throws RSIllegalArgumentException if the usage flags are not compatible |
| 1005 | * with an YUV Allocation. |
| 1006 | * @see #setPreviewCallbackAllocation |
| 1007 | * @hide |
| 1008 | */ |
| 1009 | public final Allocation createPreviewAllocation(RenderScript rs, int usage) |
| 1010 | throws RSIllegalArgumentException { |
| 1011 | Parameters p = getParameters(); |
| 1012 | Size previewSize = p.getPreviewSize(); |
| 1013 | Type.Builder yuvBuilder = new Type.Builder(rs, |
| 1014 | Element.createPixel(rs, |
| 1015 | Element.DataType.UNSIGNED_8, |
| 1016 | Element.DataKind.PIXEL_YUV)); |
| 1017 | // Use YV12 for wide compatibility. Changing this requires also |
| 1018 | // adjusting camera service's format selection. |
| 1019 | yuvBuilder.setYuvFormat(ImageFormat.YV12); |
| 1020 | yuvBuilder.setX(previewSize.width); |
| 1021 | yuvBuilder.setY(previewSize.height); |
| 1022 | |
| 1023 | Allocation a = Allocation.createTyped(rs, yuvBuilder.create(), |
| 1024 | usage | Allocation.USAGE_IO_INPUT); |
| 1025 | |
| 1026 | return a; |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * <p>Set an {@link android.renderscript.Allocation Allocation} as the |
| 1031 | * target of preview callback data. Use this method for efficient processing |
| 1032 | * of camera preview data with RenderScript. The Allocation must be created |
| 1033 | * with the {@link #createPreviewAllocation createPreviewAllocation } |
| 1034 | * method.</p> |
| 1035 | * |
| 1036 | * <p>Setting a preview allocation will disable any active preview callbacks |
| 1037 | * set by {@link #setPreviewCallback setPreviewCallback} or |
| 1038 | * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and |
| 1039 | * vice versa. Using a preview allocation still requires an active standard |
| 1040 | * preview target to be set, either with |
| 1041 | * {@link #setPreviewTexture setPreviewTexture} or |
| 1042 | * {@link #setPreviewDisplay setPreviewDisplay}.</p> |
| 1043 | * |
| 1044 | * <p>To be notified when new frames are available to the Allocation, use |
| 1045 | * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To |
| 1046 | * update the frame currently accessible from the Allocation to the latest |
| 1047 | * preview frame, call |
| 1048 | * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p> |
| 1049 | * |
| 1050 | * <p>To disable preview into the Allocation, call this method with a |
| 1051 | * {@code null} parameter.</p> |
| 1052 | * |
| 1053 | * <p>Once a preview allocation is set, the preview size set by |
| 1054 | * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If |
| 1055 | * you wish to change the preview size, first remove the preview allocation |
| 1056 | * by calling {@code setPreviewCallbackAllocation(null)}, then change the |
| 1057 | * preview size, create a new preview Allocation with |
| 1058 | * {@link #createPreviewAllocation createPreviewAllocation}, and set it as |
| 1059 | * the new preview callback allocation target.</p> |
| 1060 | * |
| 1061 | * <p>If you are using the preview data to create video or still images, |
| 1062 | * strongly consider using {@link android.media.MediaActionSound} to |
| 1063 | * properly indicate image capture or recording start/stop to the user.</p> |
| 1064 | * |
| 1065 | * @param previewAllocation the allocation to use as destination for preview |
| 1066 | * @throws IOException if configuring the camera to use the Allocation for |
| 1067 | * preview fails. |
| 1068 | * @throws IllegalArgumentException if the Allocation's dimensions or other |
| 1069 | * parameters don't meet the requirements. |
| 1070 | * @see #createPreviewAllocation |
| 1071 | * @see #setPreviewCallback |
| 1072 | * @see #setPreviewCallbackWithBuffer |
| 1073 | * @hide |
| 1074 | */ |
| 1075 | public final void setPreviewCallbackAllocation(Allocation previewAllocation) |
| 1076 | throws IOException { |
| 1077 | Surface previewSurface = null; |
| 1078 | if (previewAllocation != null) { |
| 1079 | Parameters p = getParameters(); |
| 1080 | Size previewSize = p.getPreviewSize(); |
| 1081 | if (previewSize.width != previewAllocation.getType().getX() || |
| 1082 | previewSize.height != previewAllocation.getType().getY()) { |
| 1083 | throw new IllegalArgumentException( |
| 1084 | "Allocation dimensions don't match preview dimensions: " + |
| 1085 | "Allocation is " + |
| 1086 | previewAllocation.getType().getX() + |
| 1087 | ", " + |
| 1088 | previewAllocation.getType().getY() + |
| 1089 | ". Preview is " + previewSize.width + ", " + |
| 1090 | previewSize.height); |
| 1091 | } |
| 1092 | if ((previewAllocation.getUsage() & |
| 1093 | Allocation.USAGE_IO_INPUT) == 0) { |
| 1094 | throw new IllegalArgumentException( |
| 1095 | "Allocation usage does not include USAGE_IO_INPUT"); |
| 1096 | } |
| 1097 | if (previewAllocation.getType().getElement().getDataKind() != |
| 1098 | Element.DataKind.PIXEL_YUV) { |
| 1099 | throw new IllegalArgumentException( |
| 1100 | "Allocation is not of a YUV type"); |
| 1101 | } |
| 1102 | previewSurface = previewAllocation.getSurface(); |
| 1103 | mUsingPreviewAllocation = true; |
| 1104 | } else { |
| 1105 | mUsingPreviewAllocation = false; |
| 1106 | } |
| 1107 | setPreviewCallbackSurface(previewSurface); |
| 1108 | } |
| 1109 | |
| 1110 | private native final void setPreviewCallbackSurface(Surface s); |
| 1111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | private class EventHandler extends Handler |
| 1113 | { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 1114 | private final Camera mCamera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | |
| 1116 | public EventHandler(Camera c, Looper looper) { |
| 1117 | super(looper); |
| 1118 | mCamera = c; |
| 1119 | } |
| 1120 | |
| 1121 | @Override |
| 1122 | public void handleMessage(Message msg) { |
| 1123 | switch(msg.what) { |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1124 | case CAMERA_MSG_SHUTTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | if (mShutterCallback != null) { |
| 1126 | mShutterCallback.onShutter(); |
| 1127 | } |
| 1128 | return; |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1129 | |
| 1130 | case CAMERA_MSG_RAW_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1131 | if (mRawImageCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1133 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | return; |
| 1135 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1136 | case CAMERA_MSG_COMPRESSED_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1137 | if (mJpegCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1141 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1142 | case CAMERA_MSG_PREVIEW_FRAME: |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1143 | PreviewCallback pCb = mPreviewCallback; |
| 1144 | if (pCb != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | if (mOneShot) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1146 | // Clear the callback variable before the callback |
| 1147 | // in case the app calls setPreviewCallback from |
| 1148 | // the callback function |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | mPreviewCallback = null; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1150 | } else if (!mWithBuffer) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1151 | // We're faking the camera preview mode to prevent |
| 1152 | // the app from being flooded with preview frames. |
| 1153 | // Set to oneshot mode again. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1154 | setHasPreviewCallback(true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | } |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1156 | pCb.onPreviewFrame((byte[])msg.obj, mCamera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | return; |
| 1159 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1160 | case CAMERA_MSG_POSTVIEW_FRAME: |
| 1161 | if (mPostviewCallback != null) { |
| 1162 | mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); |
| 1163 | } |
| 1164 | return; |
| 1165 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1166 | case CAMERA_MSG_FOCUS: |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1167 | AutoFocusCallback cb = null; |
| 1168 | synchronized (mAutoFocusCallbackLock) { |
| 1169 | cb = mAutoFocusCallback; |
| 1170 | } |
| 1171 | if (cb != null) { |
| 1172 | boolean success = msg.arg1 == 0 ? false : true; |
| 1173 | cb.onAutoFocus(success, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1174 | } |
| 1175 | return; |
| 1176 | |
| 1177 | case CAMERA_MSG_ZOOM: |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1178 | if (mZoomListener != null) { |
| 1179 | mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1180 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | return; |
| 1182 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1183 | case CAMERA_MSG_PREVIEW_METADATA: |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1184 | if (mFaceListener != null) { |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1185 | mFaceListener.onFaceDetection((Face[])msg.obj, mCamera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1186 | } |
| 1187 | return; |
| 1188 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1189 | case CAMERA_MSG_ERROR : |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | Log.e(TAG, "Error " + msg.arg1); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1191 | if (mErrorCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | mErrorCallback.onError(msg.arg1, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | return; |
| 1195 | |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1196 | case CAMERA_MSG_FOCUS_MOVE: |
| 1197 | if (mAutoFocusMoveCallback != null) { |
| 1198 | mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera); |
| 1199 | } |
| 1200 | return; |
| 1201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | default: |
| 1203 | Log.e(TAG, "Unknown message type " + msg.what); |
| 1204 | return; |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | private static void postEventFromNative(Object camera_ref, |
| 1210 | int what, int arg1, int arg2, Object obj) |
| 1211 | { |
| 1212 | Camera c = (Camera)((WeakReference)camera_ref).get(); |
| 1213 | if (c == null) |
| 1214 | return; |
| 1215 | |
| 1216 | if (c.mEventHandler != null) { |
| 1217 | Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); |
| 1218 | c.mEventHandler.sendMessage(m); |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1223 | * Callback interface used to notify on completion of camera auto focus. |
| 1224 | * |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1225 | * <p>Devices that do not support auto-focus will receive a "fake" |
| 1226 | * callback to this interface. If your application needs auto-focus and |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1227 | * should not be installed on devices <em>without</em> auto-focus, you must |
| 1228 | * declare that your app uses the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1229 | * {@code android.hardware.camera.autofocus} feature, in the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1230 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1231 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1232 | * |
| 1233 | * @see #autoFocus(AutoFocusCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1234 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1235 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1237 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | public interface AutoFocusCallback |
| 1239 | { |
| 1240 | /** |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1241 | * Called when the camera auto focus completes. If the camera |
| 1242 | * does not support auto-focus and autoFocus is called, |
| 1243 | * onAutoFocus will be called immediately with a fake value of |
| 1244 | * <code>success</code> set to <code>true</code>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1245 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1246 | * The auto-focus routine does not lock auto-exposure and auto-white |
| 1247 | * balance after it completes. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1248 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | * @param success true if focus was successful, false if otherwise |
| 1250 | * @param camera the Camera service object |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1251 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1252 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | */ |
| 1254 | void onAutoFocus(boolean success, Camera camera); |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | |
| 1257 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1258 | * Starts camera auto-focus and registers a callback function to run when |
| 1259 | * the camera is focused. This method is only valid when preview is active |
| 1260 | * (between {@link #startPreview()} and before {@link #stopPreview()}). |
| 1261 | * |
| 1262 | * <p>Callers should check |
| 1263 | * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if |
| 1264 | * this method should be called. If the camera does not support auto-focus, |
| 1265 | * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1266 | * callback will be called immediately. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1267 | * |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 1268 | * <p>If your application should not be installed |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1269 | * on devices without auto-focus, you must declare that your application |
| 1270 | * uses auto-focus with the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1271 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1272 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1273 | * |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1274 | * <p>If the current flash mode is not |
| 1275 | * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1276 | * fired during auto-focus, depending on the driver and camera hardware.<p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1277 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1278 | * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()} |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1279 | * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()} |
| 1280 | * do not change during and after autofocus. But auto-focus routine may stop |
| 1281 | * auto-exposure and auto-white balance transiently during focusing. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1282 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1283 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 1284 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
| 1285 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 1286 | * the focus position. Applications must call cancelAutoFocus to reset the |
| 1287 | * focus.</p> |
| 1288 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1289 | * <p>If autofocus is successful, consider using |
| 1290 | * {@link android.media.MediaActionSound} to properly play back an autofocus |
| 1291 | * success sound to the user.</p> |
| 1292 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1294 | * @throws RuntimeException if starting autofocus fails; usually this would |
| 1295 | * be because of a hardware or other low-level error, or because |
| 1296 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1297 | * @see #cancelAutoFocus() |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1298 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1299 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1300 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | */ |
| 1302 | public final void autoFocus(AutoFocusCallback cb) |
| 1303 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1304 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1305 | mAutoFocusCallback = cb; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1306 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1307 | native_autoFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | } |
| 1309 | private native final void native_autoFocus(); |
| 1310 | |
| 1311 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1312 | * Cancels any auto-focus function in progress. |
| 1313 | * Whether or not auto-focus is currently in progress, |
| 1314 | * this function will return the focus position to the default. |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1315 | * If the camera does not support auto-focus, this is a no-op. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1316 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1317 | * @throws RuntimeException if canceling autofocus fails; usually this would |
| 1318 | * be because of a hardware or other low-level error, or because |
| 1319 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1320 | * @see #autoFocus(Camera.AutoFocusCallback) |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1321 | */ |
| 1322 | public final void cancelAutoFocus() |
| 1323 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1324 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1325 | mAutoFocusCallback = null; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1326 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1327 | native_cancelAutoFocus(); |
| 1328 | // CAMERA_MSG_FOCUS should be removed here because the following |
| 1329 | // scenario can happen: |
| 1330 | // - An application uses the same thread for autoFocus, cancelAutoFocus |
| 1331 | // and looper thread. |
| 1332 | // - The application calls autoFocus. |
| 1333 | // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue. |
| 1334 | // Before event handler's handleMessage() is invoked, the application |
| 1335 | // calls cancelAutoFocus and autoFocus. |
| 1336 | // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus |
| 1337 | // has been completed. But in fact it is not. |
| 1338 | // |
| 1339 | // As documented in the beginning of the file, apps should not use |
| 1340 | // multiple threads to call autoFocus and cancelAutoFocus at the same |
| 1341 | // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS |
| 1342 | // message after native_cancelAutoFocus is called. |
| 1343 | mEventHandler.removeMessages(CAMERA_MSG_FOCUS); |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1344 | } |
| 1345 | private native final void native_cancelAutoFocus(); |
| 1346 | |
| 1347 | /** |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1348 | * Callback interface used to notify on auto focus start and stop. |
| 1349 | * |
Wu-cheng Li | 6574539 | 2012-04-12 18:07:16 +0800 | [diff] [blame] | 1350 | * <p>This is only supported in continuous autofocus modes -- {@link |
| 1351 | * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link |
| 1352 | * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show |
| 1353 | * autofocus animation based on this.</p> |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1354 | * |
| 1355 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1356 | * applications. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1357 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1358 | @Deprecated |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1359 | public interface AutoFocusMoveCallback |
| 1360 | { |
| 1361 | /** |
| 1362 | * Called when the camera auto focus starts or stops. |
| 1363 | * |
| 1364 | * @param start true if focus starts to move, false if focus stops to move |
Wu-cheng Li | 6574539 | 2012-04-12 18:07:16 +0800 | [diff] [blame] | 1365 | * @param camera the Camera service object |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1366 | */ |
| 1367 | void onAutoFocusMoving(boolean start, Camera camera); |
| 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * Sets camera auto-focus move callback. |
| 1372 | * |
| 1373 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1374 | * @throws RuntimeException if enabling the focus move callback fails; |
| 1375 | * usually this would be because of a hardware or other low-level error, |
| 1376 | * or because release() has been called on this Camera instance. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1377 | */ |
| 1378 | public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) { |
| 1379 | mAutoFocusMoveCallback = cb; |
| 1380 | enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0); |
| 1381 | } |
| 1382 | |
| 1383 | private native void enableFocusMoveCallback(int enable); |
| 1384 | |
| 1385 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1386 | * Callback interface used to signal the moment of actual image capture. |
| 1387 | * |
| 1388 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1389 | * |
| 1390 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1391 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1393 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | public interface ShutterCallback |
| 1395 | { |
| 1396 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1397 | * Called as near as possible to the moment when a photo is captured |
| 1398 | * from the sensor. This is a good opportunity to play a shutter sound |
| 1399 | * or give other feedback of camera operation. This may be some time |
| 1400 | * after the photo was triggered, but some time before the actual data |
| 1401 | * is available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | */ |
| 1403 | void onShutter(); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1407 | * Callback interface used to supply image data from a photo capture. |
| 1408 | * |
| 1409 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1410 | * |
| 1411 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1412 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1414 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | public interface PictureCallback { |
| 1416 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1417 | * Called when image data is available after a picture is taken. |
| 1418 | * The format of the data depends on the context of the callback |
| 1419 | * and {@link Camera.Parameters} settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1420 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | * @param data a byte array of the picture data |
| 1422 | * @param camera the Camera service object |
| 1423 | */ |
| 1424 | void onPictureTaken(byte[] data, Camera camera); |
| 1425 | }; |
| 1426 | |
| 1427 | /** |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1428 | * Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1429 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1430 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | */ |
| 1432 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1433 | PictureCallback jpeg) { |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1434 | takePicture(shutter, raw, null, jpeg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1436 | private native final void native_takePicture(int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1438 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1439 | * Triggers an asynchronous image capture. The camera service will initiate |
| 1440 | * a series of callbacks to the application as the image capture progresses. |
| 1441 | * The shutter callback occurs after the image is captured. This can be used |
| 1442 | * to trigger a sound to let the user know that image has been captured. The |
| 1443 | * raw callback occurs when the raw image data is available (NOTE: the data |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1444 | * will be null if there is no raw image callback buffer available or the |
| 1445 | * raw image callback buffer is not large enough to hold the raw image). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1446 | * The postview callback occurs when a scaled, fully processed postview |
| 1447 | * image is available (NOTE: not all hardware supports this). The jpeg |
| 1448 | * callback occurs when the compressed image is available. If the |
| 1449 | * application does not need a particular callback, a null can be passed |
| 1450 | * instead of a callback method. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1451 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1452 | * <p>This method is only valid when preview is active (after |
| 1453 | * {@link #startPreview()}). Preview will be stopped after the image is |
| 1454 | * taken; callers must call {@link #startPreview()} again if they want to |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 1455 | * re-start preview or take more pictures. This should not be called between |
| 1456 | * {@link android.media.MediaRecorder#start()} and |
| 1457 | * {@link android.media.MediaRecorder#stop()}. |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 1458 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1459 | * <p>After calling this method, you must not call {@link #startPreview()} |
| 1460 | * or take another picture until the JPEG callback has returned. |
| 1461 | * |
| 1462 | * @param shutter the callback for image capture moment, or null |
| 1463 | * @param raw the callback for raw (uncompressed) image data, or null |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1464 | * @param postview callback with postview image data, may be null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1465 | * @param jpeg the callback for JPEG image data, or null |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1466 | * @throws RuntimeException if starting picture capture fails; usually this |
| 1467 | * would be because of a hardware or other low-level error, or because |
| 1468 | * release() has been called on this Camera instance. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1469 | */ |
| 1470 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1471 | PictureCallback postview, PictureCallback jpeg) { |
| 1472 | mShutterCallback = shutter; |
| 1473 | mRawImageCallback = raw; |
| 1474 | mPostviewCallback = postview; |
| 1475 | mJpegCallback = jpeg; |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1476 | |
| 1477 | // If callback is not set, do not send me callbacks. |
| 1478 | int msgType = 0; |
| 1479 | if (mShutterCallback != null) { |
| 1480 | msgType |= CAMERA_MSG_SHUTTER; |
| 1481 | } |
| 1482 | if (mRawImageCallback != null) { |
| 1483 | msgType |= CAMERA_MSG_RAW_IMAGE; |
| 1484 | } |
| 1485 | if (mPostviewCallback != null) { |
| 1486 | msgType |= CAMERA_MSG_POSTVIEW_FRAME; |
| 1487 | } |
| 1488 | if (mJpegCallback != null) { |
| 1489 | msgType |= CAMERA_MSG_COMPRESSED_IMAGE; |
| 1490 | } |
| 1491 | |
| 1492 | native_takePicture(msgType); |
Wu-cheng Li | e9c6c9c | 2012-05-29 16:47:44 +0800 | [diff] [blame] | 1493 | mFaceDetectionRunning = false; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1497 | * Zooms to the requested value smoothly. The driver will notify {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1498 | * OnZoomChangeListener} of the zoom value and whether zoom is stopped at |
| 1499 | * the time. For example, suppose the current zoom is 0 and startSmoothZoom |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1500 | * is called with value 3. The |
| 1501 | * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)} |
| 1502 | * method will be called three times with zoom values 1, 2, and 3. |
| 1503 | * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. |
| 1504 | * Applications should not call startSmoothZoom again or change the zoom |
| 1505 | * value before zoom stops. If the supplied zoom value equals to the current |
| 1506 | * zoom value, no zoom callback will be generated. This method is supported |
| 1507 | * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported} |
| 1508 | * returns true. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1509 | * |
| 1510 | * @param value zoom value. The valid range is 0 to {@link |
| 1511 | * android.hardware.Camera.Parameters#getMaxZoom}. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1512 | * @throws IllegalArgumentException if the zoom value is invalid. |
| 1513 | * @throws RuntimeException if the method fails. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1514 | * @see #setZoomChangeListener(OnZoomChangeListener) |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1515 | */ |
| 1516 | public native final void startSmoothZoom(int value); |
| 1517 | |
| 1518 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1519 | * Stops the smooth zoom. Applications should wait for the {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1520 | * OnZoomChangeListener} to know when the zoom is actually stopped. This |
| 1521 | * method is supported if {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1522 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1523 | * |
| 1524 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1525 | */ |
| 1526 | public native final void stopSmoothZoom(); |
| 1527 | |
| 1528 | /** |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1529 | * Set the clockwise rotation of preview display in degrees. This affects |
| 1530 | * the preview frames and the picture displayed after snapshot. This method |
| 1531 | * is useful for portrait mode applications. Note that preview display of |
Wu-cheng Li | b982fb4 | 2010-10-19 17:19:09 +0800 | [diff] [blame] | 1532 | * front-facing cameras is flipped horizontally before the rotation, that |
| 1533 | * is, the image is reflected along the central vertical axis of the camera |
| 1534 | * sensor. So the users can see themselves as looking into a mirror. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1535 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1536 | * <p>This does not affect the order of byte array passed in {@link |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1537 | * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This |
| 1538 | * method is not allowed to be called during preview. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1539 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1540 | * <p>If you want to make the camera image show in the same orientation as |
| 1541 | * the display, you can use the following code. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1542 | * <pre> |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1543 | * public static void setCameraDisplayOrientation(Activity activity, |
| 1544 | * int cameraId, android.hardware.Camera camera) { |
| 1545 | * android.hardware.Camera.CameraInfo info = |
| 1546 | * new android.hardware.Camera.CameraInfo(); |
| 1547 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 1548 | * int rotation = activity.getWindowManager().getDefaultDisplay() |
| 1549 | * .getRotation(); |
| 1550 | * int degrees = 0; |
| 1551 | * switch (rotation) { |
| 1552 | * case Surface.ROTATION_0: degrees = 0; break; |
| 1553 | * case Surface.ROTATION_90: degrees = 90; break; |
| 1554 | * case Surface.ROTATION_180: degrees = 180; break; |
| 1555 | * case Surface.ROTATION_270: degrees = 270; break; |
| 1556 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1557 | * |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1558 | * int result; |
| 1559 | * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { |
| 1560 | * result = (info.orientation + degrees) % 360; |
| 1561 | * result = (360 - result) % 360; // compensate the mirror |
| 1562 | * } else { // back-facing |
| 1563 | * result = (info.orientation - degrees + 360) % 360; |
| 1564 | * } |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1565 | * camera.setDisplayOrientation(result); |
| 1566 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1567 | * </pre> |
Wu-cheng Li | d303362 | 2011-10-07 13:13:54 +0800 | [diff] [blame] | 1568 | * |
| 1569 | * <p>Starting from API level 14, this method can be called when preview is |
| 1570 | * active. |
| 1571 | * |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1572 | * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in |
| 1573 | * API level 24, the default orientation will be such that applications in forced-landscape mode |
| 1574 | * will have correct preview orientation, which may be either a default of 0 or |
| 1575 | * 180. Applications that operate in portrait mode or allow for changing orientation must still |
| 1576 | * call this method after each orientation change to ensure correct preview display in all |
| 1577 | * cases.</p> |
| 1578 | * |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1579 | * @param degrees the angle that the picture will be rotated clockwise. |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1580 | * Valid values are 0, 90, 180, and 270. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1581 | * @throws RuntimeException if setting orientation fails; usually this would |
| 1582 | * be because of a hardware or other low-level error, or because |
| 1583 | * release() has been called on this Camera instance. |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1584 | * @see #setPreviewDisplay(SurfaceHolder) |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1585 | */ |
| 1586 | public native final void setDisplayOrientation(int degrees); |
| 1587 | |
| 1588 | /** |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1589 | * <p>Enable or disable the default shutter sound when taking a picture.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1590 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1591 | * <p>By default, the camera plays the system-defined camera shutter sound |
| 1592 | * when {@link #takePicture} is called. Using this method, the shutter sound |
| 1593 | * can be disabled. It is strongly recommended that an alternative shutter |
| 1594 | * sound is played in the {@link ShutterCallback} when the system shutter |
| 1595 | * sound is disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1596 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1597 | * <p>Note that devices may not always allow disabling the camera shutter |
| 1598 | * sound. If the shutter sound state cannot be set to the desired value, |
| 1599 | * this method will return false. {@link CameraInfo#canDisableShutterSound} |
| 1600 | * can be used to determine whether the device will allow the shutter sound |
| 1601 | * to be disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1602 | * |
| 1603 | * @param enabled whether the camera should play the system shutter sound |
| 1604 | * when {@link #takePicture takePicture} is called. |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1605 | * @return {@code true} if the shutter sound state was successfully |
| 1606 | * changed. {@code false} if the shutter sound state could not be |
| 1607 | * changed. {@code true} is also returned if shutter sound playback |
| 1608 | * is already set to the requested state. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1609 | * @throws RuntimeException if the call fails; usually this would be because |
| 1610 | * of a hardware or other low-level error, or because release() has been |
| 1611 | * called on this Camera instance. |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1612 | * @see #takePicture |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1613 | * @see CameraInfo#canDisableShutterSound |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1614 | * @see ShutterCallback |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1615 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1616 | public final boolean enableShutterSound(boolean enabled) { |
| 1617 | if (!enabled) { |
| 1618 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 1619 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 1620 | try { |
| 1621 | if (audioService.isCameraSoundForced()) return false; |
| 1622 | } catch (RemoteException e) { |
| 1623 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 1624 | } |
| 1625 | } |
| 1626 | return _enableShutterSound(enabled); |
| 1627 | } |
| 1628 | |
Igor Murashkin | 6653362 | 2014-08-19 14:51:47 -0700 | [diff] [blame] | 1629 | /** |
| 1630 | * Disable the shutter sound unconditionally. |
| 1631 | * |
| 1632 | * <p> |
| 1633 | * This is only guaranteed to work for legacy cameras |
| 1634 | * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on |
| 1635 | * a regular camera will force a conditional check in the camera service. |
| 1636 | * </p> |
| 1637 | * |
| 1638 | * @return {@code true} if the shutter sound state was successfully |
| 1639 | * changed. {@code false} if the shutter sound state could not be |
| 1640 | * changed. {@code true} is also returned if shutter sound playback |
| 1641 | * is already set to the requested state. |
| 1642 | * |
| 1643 | * @hide |
| 1644 | */ |
| 1645 | public final boolean disableShutterSound() { |
| 1646 | return _enableShutterSound(/*enabled*/false); |
| 1647 | } |
| 1648 | |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1649 | private native final boolean _enableShutterSound(boolean enabled); |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1650 | |
| 1651 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1652 | * Callback interface for zoom changes during a smooth zoom operation. |
| 1653 | * |
| 1654 | * @see #setZoomChangeListener(OnZoomChangeListener) |
| 1655 | * @see #startSmoothZoom(int) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1656 | * |
| 1657 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1658 | * applications. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1659 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1660 | @Deprecated |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1661 | public interface OnZoomChangeListener |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1662 | { |
| 1663 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1664 | * Called when the zoom value has changed during a smooth zoom. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1665 | * |
| 1666 | * @param zoomValue the current zoom value. In smooth zoom mode, camera |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1667 | * calls this for every new zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1668 | * @param stopped whether smooth zoom is stopped. If the value is true, |
| 1669 | * this is the last zoom update for the application. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1670 | * @param camera the Camera service object |
| 1671 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1672 | void onZoomChange(int zoomValue, boolean stopped, Camera camera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1673 | }; |
| 1674 | |
| 1675 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1676 | * Registers a listener to be notified when the zoom value is updated by the |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1677 | * camera driver during smooth zoom. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1678 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1679 | * @param listener the listener to notify |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1680 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1681 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1682 | public final void setZoomChangeListener(OnZoomChangeListener listener) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1683 | { |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1684 | mZoomListener = listener; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1685 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1686 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1687 | /** |
| 1688 | * Callback interface for face detected in the preview frame. |
| 1689 | * |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1690 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1691 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1692 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1693 | @Deprecated |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1694 | public interface FaceDetectionListener |
| 1695 | { |
| 1696 | /** |
| 1697 | * Notify the listener of the detected faces in the preview frame. |
| 1698 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1699 | * @param faces The detected faces in a list |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1700 | * @param camera The {@link Camera} service object |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1701 | */ |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1702 | void onFaceDetection(Face[] faces, Camera camera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1706 | * Registers a listener to be notified about the faces detected in the |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1707 | * preview frame. |
| 1708 | * |
| 1709 | * @param listener the listener to notify |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1710 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1711 | */ |
| 1712 | public final void setFaceDetectionListener(FaceDetectionListener listener) |
| 1713 | { |
| 1714 | mFaceListener = listener; |
| 1715 | } |
| 1716 | |
| 1717 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1718 | * Starts the face detection. This should be called after preview is started. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1719 | * The camera will notify {@link FaceDetectionListener} of the detected |
| 1720 | * faces in the preview frame. The detected faces may be the same as the |
| 1721 | * previous ones. Applications should call {@link #stopFaceDetection} to |
| 1722 | * stop the face detection. This method is supported if {@link |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1723 | * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1724 | * If the face detection has started, apps should not call this again. |
| 1725 | * |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1726 | * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1727 | * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1728 | * have no effect. The camera uses the detected faces to do auto-white balance, |
| 1729 | * auto exposure, and autofocus. |
| 1730 | * |
| 1731 | * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera |
| 1732 | * will stop sending face callbacks. The last face callback indicates the |
| 1733 | * areas used to do autofocus. After focus completes, face detection will |
| 1734 | * resume sending face callbacks. If the apps call {@link |
| 1735 | * #cancelAutoFocus()}, the face callbacks will also resume.</p> |
| 1736 | * |
| 1737 | * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 1738 | * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming |
| 1739 | * preview with {@link #startPreview()}, the apps should call this method |
| 1740 | * again to resume face detection.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1741 | * |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1742 | * @throws IllegalArgumentException if the face detection is unsupported. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1743 | * @throws RuntimeException if the method fails or the face detection is |
| 1744 | * already running. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1745 | * @see FaceDetectionListener |
| 1746 | * @see #stopFaceDetection() |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1747 | * @see Parameters#getMaxNumDetectedFaces() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1748 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1749 | public final void startFaceDetection() { |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1750 | if (mFaceDetectionRunning) { |
| 1751 | throw new RuntimeException("Face detection is already running"); |
| 1752 | } |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1753 | _startFaceDetection(CAMERA_FACE_DETECTION_HW); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1754 | mFaceDetectionRunning = true; |
| 1755 | } |
| 1756 | |
| 1757 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1758 | * Stops the face detection. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1759 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1760 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1761 | */ |
| 1762 | public final void stopFaceDetection() { |
| 1763 | _stopFaceDetection(); |
| 1764 | mFaceDetectionRunning = false; |
| 1765 | } |
| 1766 | |
| 1767 | private native final void _startFaceDetection(int type); |
| 1768 | private native final void _stopFaceDetection(); |
| 1769 | |
| 1770 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1771 | * Information about a face identified through camera face detection. |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1772 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1773 | * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a |
| 1774 | * list of face objects for use in focusing and metering.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1775 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1776 | * @see FaceDetectionListener |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1777 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1778 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1779 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1780 | @Deprecated |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1781 | public static class Face { |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1782 | /** |
| 1783 | * Create an empty face. |
| 1784 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1785 | public Face() { |
| 1786 | } |
| 1787 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1788 | /** |
| 1789 | * Bounds of the face. (-1000, -1000) represents the top-left of the |
| 1790 | * camera field of view, and (1000, 1000) represents the bottom-right of |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1791 | * the field of view. For example, suppose the size of the viewfinder UI |
| 1792 | * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1793 | * The corresponding viewfinder rect should be (0, 0, 400, 240). It is |
| 1794 | * guaranteed left < right and top < bottom. The coordinates can be |
| 1795 | * smaller than -1000 or bigger than 1000. But at least one vertex will |
| 1796 | * be within (-1000, -1000) and (1000, 1000). |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1797 | * |
| 1798 | * <p>The direction is relative to the sensor orientation, that is, what |
| 1799 | * the sensor sees. The direction is not affected by the rotation or |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1800 | * mirroring of {@link #setDisplayOrientation(int)}. The face bounding |
| 1801 | * rectangle does not provide any information about face orientation.</p> |
| 1802 | * |
| 1803 | * <p>Here is the matrix to convert driver coordinates to View coordinates |
| 1804 | * in pixels.</p> |
| 1805 | * <pre> |
| 1806 | * Matrix matrix = new Matrix(); |
| 1807 | * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; |
| 1808 | * // Need mirror for front camera. |
| 1809 | * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); |
| 1810 | * matrix.setScale(mirror ? -1 : 1, 1); |
| 1811 | * // This is the value for android.hardware.Camera.setDisplayOrientation. |
| 1812 | * matrix.postRotate(displayOrientation); |
| 1813 | * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). |
| 1814 | * // UI coordinates range from (0, 0) to (width, height). |
| 1815 | * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); |
| 1816 | * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); |
| 1817 | * </pre> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1818 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1819 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1820 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1821 | public Rect rect; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1822 | |
| 1823 | /** |
Eino-Ville Talvala | 8df3b2b | 2012-09-15 14:30:12 -0700 | [diff] [blame] | 1824 | * <p>The confidence level for the detection of the face. The range is 1 to |
| 1825 | * 100. 100 is the highest confidence.</p> |
| 1826 | * |
| 1827 | * <p>Depending on the device, even very low-confidence faces may be |
| 1828 | * listed, so applications should filter out faces with low confidence, |
| 1829 | * depending on the use case. For a typical point-and-shoot camera |
| 1830 | * application that wishes to display rectangles around detected faces, |
| 1831 | * filtering out faces with confidence less than 50 is recommended.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1832 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1833 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1834 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1835 | public int score; |
Wei Hua | d52b308 | 2011-08-19 13:01:51 -0700 | [diff] [blame] | 1836 | |
| 1837 | /** |
| 1838 | * An unique id per face while the face is visible to the tracker. If |
| 1839 | * the face leaves the field-of-view and comes back, it will get a new |
| 1840 | * id. This is an optional field, may not be supported on all devices. |
| 1841 | * If not supported, id will always be set to -1. The optional fields |
| 1842 | * are supported as a set. Either they are all valid, or none of them |
| 1843 | * are. |
| 1844 | */ |
| 1845 | public int id = -1; |
| 1846 | |
| 1847 | /** |
| 1848 | * The coordinates of the center of the left eye. The coordinates are in |
| 1849 | * the same space as the ones for {@link #rect}. This is an optional |
| 1850 | * field, may not be supported on all devices. If not supported, the |
| 1851 | * value will always be set to null. The optional fields are supported |
| 1852 | * as a set. Either they are all valid, or none of them are. |
| 1853 | */ |
| 1854 | public Point leftEye = null; |
| 1855 | |
| 1856 | /** |
| 1857 | * The coordinates of the center of the right eye. The coordinates are |
| 1858 | * in the same space as the ones for {@link #rect}.This is an optional |
| 1859 | * field, may not be supported on all devices. If not supported, the |
| 1860 | * value will always be set to null. The optional fields are supported |
| 1861 | * as a set. Either they are all valid, or none of them are. |
| 1862 | */ |
| 1863 | public Point rightEye = null; |
| 1864 | |
| 1865 | /** |
| 1866 | * The coordinates of the center of the mouth. The coordinates are in |
| 1867 | * the same space as the ones for {@link #rect}. This is an optional |
| 1868 | * field, may not be supported on all devices. If not supported, the |
| 1869 | * value will always be set to null. The optional fields are supported |
| 1870 | * as a set. Either they are all valid, or none of them are. |
| 1871 | */ |
| 1872 | public Point mouth = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1873 | } |
| 1874 | |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1875 | /** |
| 1876 | * Unspecified camera error. |
| 1877 | * @see Camera.ErrorCallback |
| 1878 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | public static final int CAMERA_ERROR_UNKNOWN = 1; |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1880 | |
| 1881 | /** |
Ruben Brunk | e91b925 | 2015-04-14 13:38:06 -0700 | [diff] [blame] | 1882 | * Camera was disconnected due to use by higher priority user. |
| 1883 | * @see Camera.ErrorCallback |
| 1884 | */ |
| 1885 | public static final int CAMERA_ERROR_EVICTED = 2; |
| 1886 | |
| 1887 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1888 | * Media server died. In this case, the application must release the |
| 1889 | * Camera object and instantiate a new one. |
| 1890 | * @see Camera.ErrorCallback |
| 1891 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | public static final int CAMERA_ERROR_SERVER_DIED = 100; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1895 | * Callback interface for camera error notification. |
| 1896 | * |
| 1897 | * @see #setErrorCallback(ErrorCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1898 | * |
| 1899 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1900 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1902 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | public interface ErrorCallback |
| 1904 | { |
| 1905 | /** |
| 1906 | * Callback for camera errors. |
| 1907 | * @param error error code: |
| 1908 | * <ul> |
| 1909 | * <li>{@link #CAMERA_ERROR_UNKNOWN} |
| 1910 | * <li>{@link #CAMERA_ERROR_SERVER_DIED} |
| 1911 | * </ul> |
| 1912 | * @param camera the Camera service object |
| 1913 | */ |
| 1914 | void onError(int error, Camera camera); |
| 1915 | }; |
| 1916 | |
| 1917 | /** |
| 1918 | * Registers a callback to be invoked when an error occurs. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1919 | * @param cb The callback to run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | */ |
| 1921 | public final void setErrorCallback(ErrorCallback cb) |
| 1922 | { |
| 1923 | mErrorCallback = cb; |
| 1924 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | private native final void native_setParameters(String params); |
| 1927 | private native final String native_getParameters(); |
| 1928 | |
| 1929 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1930 | * Changes the settings for this Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1931 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | * @param params the Parameters to use for this Camera service |
Wu-cheng Li | 99a3f3e | 2010-11-19 15:56:16 +0800 | [diff] [blame] | 1933 | * @throws RuntimeException if any parameter is invalid or not supported. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1934 | * @see #getParameters() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | */ |
| 1936 | public void setParameters(Parameters params) { |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 1937 | // If using preview allocations, don't allow preview size changes |
| 1938 | if (mUsingPreviewAllocation) { |
| 1939 | Size newPreviewSize = params.getPreviewSize(); |
| 1940 | Size currentPreviewSize = getParameters().getPreviewSize(); |
| 1941 | if (newPreviewSize.width != currentPreviewSize.width || |
| 1942 | newPreviewSize.height != currentPreviewSize.height) { |
| 1943 | throw new IllegalStateException("Cannot change preview size" + |
| 1944 | " while a preview allocation is configured."); |
| 1945 | } |
| 1946 | } |
| 1947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | native_setParameters(params.flatten()); |
| 1949 | } |
| 1950 | |
| 1951 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1952 | * Returns the current settings for this Camera service. |
| 1953 | * If modifications are made to the returned Parameters, they must be passed |
| 1954 | * to {@link #setParameters(Camera.Parameters)} to take effect. |
| 1955 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1956 | * @throws RuntimeException if reading parameters fails; usually this would |
| 1957 | * be because of a hardware or other low-level error, or because |
| 1958 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1959 | * @see #setParameters(Camera.Parameters) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | */ |
| 1961 | public Parameters getParameters() { |
| 1962 | Parameters p = new Parameters(); |
| 1963 | String s = native_getParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | p.unflatten(s); |
| 1965 | return p; |
| 1966 | } |
| 1967 | |
| 1968 | /** |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 1969 | * Returns an empty {@link Parameters} for testing purpose. |
| 1970 | * |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 1971 | * @return a Parameter object. |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 1972 | * |
| 1973 | * @hide |
| 1974 | */ |
| 1975 | public static Parameters getEmptyParameters() { |
| 1976 | Camera camera = new Camera(); |
| 1977 | return camera.new Parameters(); |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 1981 | * Returns a copied {@link Parameters}; for shim use only. |
| 1982 | * |
| 1983 | * @param parameters a non-{@code null} parameters |
| 1984 | * @return a Parameter object, with all the parameters copied from {@code parameters}. |
| 1985 | * |
| 1986 | * @throws NullPointerException if {@code parameters} was {@code null} |
| 1987 | * @hide |
| 1988 | */ |
| 1989 | public static Parameters getParametersCopy(Camera.Parameters parameters) { |
| 1990 | if (parameters == null) { |
| 1991 | throw new NullPointerException("parameters must not be null"); |
| 1992 | } |
| 1993 | |
| 1994 | Camera camera = parameters.getOuter(); |
| 1995 | Parameters p = camera.new Parameters(); |
| 1996 | p.copyFrom(parameters); |
| 1997 | |
| 1998 | return p; |
| 1999 | } |
| 2000 | |
| 2001 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2002 | * Image size (width and height dimensions). |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2003 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2004 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2006 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | public class Size { |
| 2008 | /** |
| 2009 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2010 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | * @param w the photo width (pixels) |
| 2012 | * @param h the photo height (pixels) |
| 2013 | */ |
| 2014 | public Size(int w, int h) { |
| 2015 | width = w; |
| 2016 | height = h; |
| 2017 | } |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2018 | /** |
| 2019 | * Compares {@code obj} to this size. |
| 2020 | * |
| 2021 | * @param obj the object to compare this size with. |
| 2022 | * @return {@code true} if the width and height of {@code obj} is the |
| 2023 | * same as those of this size. {@code false} otherwise. |
| 2024 | */ |
| 2025 | @Override |
| 2026 | public boolean equals(Object obj) { |
| 2027 | if (!(obj instanceof Size)) { |
| 2028 | return false; |
| 2029 | } |
| 2030 | Size s = (Size) obj; |
| 2031 | return width == s.width && height == s.height; |
| 2032 | } |
| 2033 | @Override |
| 2034 | public int hashCode() { |
| 2035 | return width * 32713 + height; |
| 2036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | /** width of the picture */ |
| 2038 | public int width; |
| 2039 | /** height of the picture */ |
| 2040 | public int height; |
| 2041 | }; |
| 2042 | |
| 2043 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2044 | * <p>The Area class is used for choosing specific metering and focus areas for |
| 2045 | * the camera to use when calculating auto-exposure, auto-white balance, and |
| 2046 | * auto-focus.</p> |
| 2047 | * |
| 2048 | * <p>To find out how many simultaneous areas a given camera supports, use |
| 2049 | * {@link Parameters#getMaxNumMeteringAreas()} and |
| 2050 | * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area |
| 2051 | * selection is unsupported, these methods will return 0.</p> |
| 2052 | * |
| 2053 | * <p>Each Area consists of a rectangle specifying its bounds, and a weight |
| 2054 | * that determines its importance. The bounds are relative to the camera's |
| 2055 | * current field of view. The coordinates are mapped so that (-1000, -1000) |
| 2056 | * is always the top-left corner of the current field of view, and (1000, |
| 2057 | * 1000) is always the bottom-right corner of the current field of |
| 2058 | * view. Setting Areas with bounds outside that range is not allowed. Areas |
| 2059 | * with zero or negative width or height are not allowed.</p> |
| 2060 | * |
| 2061 | * <p>The weight must range from 1 to 1000, and represents a weight for |
| 2062 | * every pixel in the area. This means that a large metering area with |
| 2063 | * the same weight as a smaller area will have more effect in the |
| 2064 | * metering result. Metering areas can overlap and the driver |
| 2065 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2066 | * |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2067 | * @see Parameters#setFocusAreas(List) |
| 2068 | * @see Parameters#getFocusAreas() |
| 2069 | * @see Parameters#getMaxNumFocusAreas() |
| 2070 | * @see Parameters#setMeteringAreas(List) |
| 2071 | * @see Parameters#getMeteringAreas() |
| 2072 | * @see Parameters#getMaxNumMeteringAreas() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2073 | * |
| 2074 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2075 | * applications. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2076 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2077 | @Deprecated |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2078 | public static class Area { |
| 2079 | /** |
| 2080 | * Create an area with specified rectangle and weight. |
| 2081 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2082 | * @param rect the bounds of the area. |
| 2083 | * @param weight the weight of the area. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2084 | */ |
| 2085 | public Area(Rect rect, int weight) { |
| 2086 | this.rect = rect; |
| 2087 | this.weight = weight; |
| 2088 | } |
| 2089 | /** |
| 2090 | * Compares {@code obj} to this area. |
| 2091 | * |
| 2092 | * @param obj the object to compare this area with. |
| 2093 | * @return {@code true} if the rectangle and weight of {@code obj} is |
| 2094 | * the same as those of this area. {@code false} otherwise. |
| 2095 | */ |
| 2096 | @Override |
| 2097 | public boolean equals(Object obj) { |
| 2098 | if (!(obj instanceof Area)) { |
| 2099 | return false; |
| 2100 | } |
| 2101 | Area a = (Area) obj; |
| 2102 | if (rect == null) { |
| 2103 | if (a.rect != null) return false; |
| 2104 | } else { |
| 2105 | if (!rect.equals(a.rect)) return false; |
| 2106 | } |
| 2107 | return weight == a.weight; |
| 2108 | } |
| 2109 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2110 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2111 | * Bounds of the area. (-1000, -1000) represents the top-left of the |
| 2112 | * camera field of view, and (1000, 1000) represents the bottom-right of |
| 2113 | * the field of view. Setting bounds outside that range is not |
| 2114 | * allowed. Bounds with zero or negative width or height are not |
| 2115 | * allowed. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2116 | * |
| 2117 | * @see Parameters#getFocusAreas() |
| 2118 | * @see Parameters#getMeteringAreas() |
| 2119 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2120 | public Rect rect; |
| 2121 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2122 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2123 | * Weight of the area. The weight must range from 1 to 1000, and |
| 2124 | * represents a weight for every pixel in the area. This means that a |
| 2125 | * large metering area with the same weight as a smaller area will have |
| 2126 | * more effect in the metering result. Metering areas can overlap and |
| 2127 | * the driver will add the weights in the overlap region. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2128 | * |
| 2129 | * @see Parameters#getFocusAreas() |
| 2130 | * @see Parameters#getMeteringAreas() |
| 2131 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2132 | public int weight; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2133 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2134 | |
| 2135 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2136 | * Camera service settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2137 | * |
| 2138 | * <p>To make camera parameters take effect, applications have to call |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2139 | * {@link Camera#setParameters(Camera.Parameters)}. For example, after |
| 2140 | * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not |
| 2141 | * actually changed until {@link Camera#setParameters(Camera.Parameters)} |
| 2142 | * is called with the changed parameters object. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2143 | * |
| 2144 | * <p>Different devices may have different camera capabilities, such as |
| 2145 | * picture size or flash modes. The application should query the camera |
| 2146 | * capabilities before setting parameters. For example, the application |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2147 | * should call {@link Camera.Parameters#getSupportedColorEffects()} before |
| 2148 | * calling {@link Camera.Parameters#setColorEffect(String)}. If the |
| 2149 | * camera does not support color effects, |
| 2150 | * {@link Camera.Parameters#getSupportedColorEffects()} will return null. |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2151 | * |
| 2152 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2153 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2155 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2156 | public class Parameters { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2157 | // Parameter keys to communicate with the camera driver. |
| 2158 | private static final String KEY_PREVIEW_SIZE = "preview-size"; |
| 2159 | private static final String KEY_PREVIEW_FORMAT = "preview-format"; |
| 2160 | private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2161 | private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2162 | private static final String KEY_PICTURE_SIZE = "picture-size"; |
| 2163 | private static final String KEY_PICTURE_FORMAT = "picture-format"; |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2164 | private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2165 | private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; |
| 2166 | private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; |
| 2167 | private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; |
| 2168 | private static final String KEY_JPEG_QUALITY = "jpeg-quality"; |
| 2169 | private static final String KEY_ROTATION = "rotation"; |
| 2170 | private static final String KEY_GPS_LATITUDE = "gps-latitude"; |
| 2171 | private static final String KEY_GPS_LONGITUDE = "gps-longitude"; |
| 2172 | private static final String KEY_GPS_ALTITUDE = "gps-altitude"; |
| 2173 | private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 2174 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2175 | private static final String KEY_WHITE_BALANCE = "whitebalance"; |
| 2176 | private static final String KEY_EFFECT = "effect"; |
| 2177 | private static final String KEY_ANTIBANDING = "antibanding"; |
| 2178 | private static final String KEY_SCENE_MODE = "scene-mode"; |
| 2179 | private static final String KEY_FLASH_MODE = "flash-mode"; |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2180 | private static final String KEY_FOCUS_MODE = "focus-mode"; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2181 | private static final String KEY_FOCUS_AREAS = "focus-areas"; |
| 2182 | private static final String KEY_MAX_NUM_FOCUS_AREAS = "max-num-focus-areas"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 2183 | private static final String KEY_FOCAL_LENGTH = "focal-length"; |
| 2184 | private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; |
| 2185 | private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2186 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2187 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; |
| 2188 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; |
| 2189 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2190 | private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock"; |
| 2191 | private static final String KEY_AUTO_EXPOSURE_LOCK_SUPPORTED = "auto-exposure-lock-supported"; |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 2192 | private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock"; |
| 2193 | private static final String KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED = "auto-whitebalance-lock-supported"; |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2194 | private static final String KEY_METERING_AREAS = "metering-areas"; |
| 2195 | private static final String KEY_MAX_NUM_METERING_AREAS = "max-num-metering-areas"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2196 | private static final String KEY_ZOOM = "zoom"; |
| 2197 | private static final String KEY_MAX_ZOOM = "max-zoom"; |
| 2198 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; |
| 2199 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; |
| 2200 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2201 | private static final String KEY_FOCUS_DISTANCES = "focus-distances"; |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2202 | private static final String KEY_VIDEO_SIZE = "video-size"; |
| 2203 | private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = |
| 2204 | "preferred-preview-size-for-video"; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2205 | private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw"; |
| 2206 | private static final String KEY_MAX_NUM_DETECTED_FACES_SW = "max-num-detected-faces-sw"; |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 2207 | private static final String KEY_RECORDING_HINT = "recording-hint"; |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 2208 | private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported"; |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 2209 | private static final String KEY_VIDEO_STABILIZATION = "video-stabilization"; |
| 2210 | private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2211 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2212 | // Parameter key suffix for supported values. |
| 2213 | private static final String SUPPORTED_VALUES_SUFFIX = "-values"; |
| 2214 | |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2215 | private static final String TRUE = "true"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2216 | private static final String FALSE = "false"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2217 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2218 | // Values for white balance settings. |
| 2219 | public static final String WHITE_BALANCE_AUTO = "auto"; |
| 2220 | public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; |
| 2221 | public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; |
| 2222 | public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; |
| 2223 | public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; |
| 2224 | public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; |
| 2225 | public static final String WHITE_BALANCE_TWILIGHT = "twilight"; |
| 2226 | public static final String WHITE_BALANCE_SHADE = "shade"; |
| 2227 | |
| 2228 | // Values for color effect settings. |
| 2229 | public static final String EFFECT_NONE = "none"; |
| 2230 | public static final String EFFECT_MONO = "mono"; |
| 2231 | public static final String EFFECT_NEGATIVE = "negative"; |
| 2232 | public static final String EFFECT_SOLARIZE = "solarize"; |
| 2233 | public static final String EFFECT_SEPIA = "sepia"; |
| 2234 | public static final String EFFECT_POSTERIZE = "posterize"; |
| 2235 | public static final String EFFECT_WHITEBOARD = "whiteboard"; |
| 2236 | public static final String EFFECT_BLACKBOARD = "blackboard"; |
| 2237 | public static final String EFFECT_AQUA = "aqua"; |
| 2238 | |
| 2239 | // Values for antibanding settings. |
| 2240 | public static final String ANTIBANDING_AUTO = "auto"; |
| 2241 | public static final String ANTIBANDING_50HZ = "50hz"; |
| 2242 | public static final String ANTIBANDING_60HZ = "60hz"; |
| 2243 | public static final String ANTIBANDING_OFF = "off"; |
| 2244 | |
| 2245 | // Values for flash mode settings. |
| 2246 | /** |
| 2247 | * Flash will not be fired. |
| 2248 | */ |
| 2249 | public static final String FLASH_MODE_OFF = "off"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2250 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2251 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2252 | * Flash will be fired automatically when required. The flash may be fired |
| 2253 | * during preview, auto-focus, or snapshot depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2254 | */ |
| 2255 | public static final String FLASH_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2256 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2257 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2258 | * Flash will always be fired during snapshot. The flash may also be |
| 2259 | * fired during preview or auto-focus depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2260 | */ |
| 2261 | public static final String FLASH_MODE_ON = "on"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2262 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2263 | /** |
| 2264 | * Flash will be fired in red-eye reduction mode. |
| 2265 | */ |
| 2266 | public static final String FLASH_MODE_RED_EYE = "red-eye"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2267 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2268 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2269 | * Constant emission of light during preview, auto-focus and snapshot. |
| 2270 | * This can also be used for video recording. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2271 | */ |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2272 | public static final String FLASH_MODE_TORCH = "torch"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2273 | |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2274 | /** |
| 2275 | * Scene mode is off. |
| 2276 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2277 | public static final String SCENE_MODE_AUTO = "auto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2278 | |
| 2279 | /** |
| 2280 | * Take photos of fast moving objects. Same as {@link |
| 2281 | * #SCENE_MODE_SPORTS}. |
| 2282 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2283 | public static final String SCENE_MODE_ACTION = "action"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2284 | |
| 2285 | /** |
| 2286 | * Take people pictures. |
| 2287 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2288 | public static final String SCENE_MODE_PORTRAIT = "portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2289 | |
| 2290 | /** |
| 2291 | * Take pictures on distant objects. |
| 2292 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2293 | public static final String SCENE_MODE_LANDSCAPE = "landscape"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2294 | |
| 2295 | /** |
| 2296 | * Take photos at night. |
| 2297 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2298 | public static final String SCENE_MODE_NIGHT = "night"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2299 | |
| 2300 | /** |
| 2301 | * Take people pictures at night. |
| 2302 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2303 | public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2304 | |
| 2305 | /** |
| 2306 | * Take photos in a theater. Flash light is off. |
| 2307 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2308 | public static final String SCENE_MODE_THEATRE = "theatre"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2309 | |
| 2310 | /** |
| 2311 | * Take pictures on the beach. |
| 2312 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2313 | public static final String SCENE_MODE_BEACH = "beach"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2314 | |
| 2315 | /** |
| 2316 | * Take pictures on the snow. |
| 2317 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2318 | public static final String SCENE_MODE_SNOW = "snow"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2319 | |
| 2320 | /** |
| 2321 | * Take sunset photos. |
| 2322 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2323 | public static final String SCENE_MODE_SUNSET = "sunset"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2324 | |
| 2325 | /** |
| 2326 | * Avoid blurry pictures (for example, due to hand shake). |
| 2327 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2328 | public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2329 | |
| 2330 | /** |
| 2331 | * For shooting firework displays. |
| 2332 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2333 | public static final String SCENE_MODE_FIREWORKS = "fireworks"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2334 | |
| 2335 | /** |
| 2336 | * Take photos of fast moving objects. Same as {@link |
| 2337 | * #SCENE_MODE_ACTION}. |
| 2338 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2339 | public static final String SCENE_MODE_SPORTS = "sports"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2340 | |
| 2341 | /** |
| 2342 | * Take indoor low-light shot. |
| 2343 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2344 | public static final String SCENE_MODE_PARTY = "party"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2345 | |
| 2346 | /** |
| 2347 | * Capture the naturally warm color of scenes lit by candles. |
| 2348 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2349 | public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; |
| 2350 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2351 | /** |
| 2352 | * Applications are looking for a barcode. Camera driver will be |
| 2353 | * optimized for barcode reading. |
| 2354 | */ |
| 2355 | public static final String SCENE_MODE_BARCODE = "barcode"; |
| 2356 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2357 | /** |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2358 | * Capture a scene using high dynamic range imaging techniques. The |
| 2359 | * camera will return an image that has an extended dynamic range |
| 2360 | * compared to a regular capture. Capturing such an image may take |
| 2361 | * longer than a regular capture. |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2362 | */ |
| 2363 | public static final String SCENE_MODE_HDR = "hdr"; |
| 2364 | |
| 2365 | /** |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2366 | * Auto-focus mode. Applications should call {@link |
| 2367 | * #autoFocus(AutoFocusCallback)} to start the focus in this mode. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2368 | */ |
| 2369 | public static final String FOCUS_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2370 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2371 | /** |
| 2372 | * Focus is set at infinity. Applications should not call |
| 2373 | * {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2374 | */ |
| 2375 | public static final String FOCUS_MODE_INFINITY = "infinity"; |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2376 | |
| 2377 | /** |
| 2378 | * Macro (close-up) focus mode. Applications should call |
| 2379 | * {@link #autoFocus(AutoFocusCallback)} to start the focus in this |
| 2380 | * mode. |
| 2381 | */ |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2382 | public static final String FOCUS_MODE_MACRO = "macro"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2383 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2384 | /** |
| 2385 | * Focus is fixed. The camera is always in this mode if the focus is not |
| 2386 | * adjustable. If the camera has auto-focus, this mode can fix the |
| 2387 | * focus, which is usually at hyperfocal distance. Applications should |
| 2388 | * not call {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2389 | */ |
| 2390 | public static final String FOCUS_MODE_FIXED = "fixed"; |
| 2391 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2392 | /** |
| 2393 | * Extended depth of field (EDOF). Focusing is done digitally and |
| 2394 | * continuously. Applications should not call {@link |
| 2395 | * #autoFocus(AutoFocusCallback)} in this mode. |
| 2396 | */ |
| 2397 | public static final String FOCUS_MODE_EDOF = "edof"; |
| 2398 | |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2399 | /** |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2400 | * Continuous auto focus mode intended for video recording. The camera |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2401 | * continuously tries to focus. This is the best choice for video |
| 2402 | * recording because the focus changes smoothly . Applications still can |
| 2403 | * call {@link #takePicture(Camera.ShutterCallback, |
| 2404 | * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the |
| 2405 | * subject may not be in focus. Auto focus starts when the parameter is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 2406 | * set. |
| 2407 | * |
| 2408 | * <p>Since API level 14, applications can call {@link |
| 2409 | * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will |
| 2410 | * immediately return with a boolean that indicates whether the focus is |
| 2411 | * sharp or not. The focus position is locked after autoFocus call. If |
| 2412 | * applications want to resume the continuous focus, cancelAutoFocus |
| 2413 | * must be called. Restarting the preview will not resume the continuous |
| 2414 | * autofocus. To stop continuous focus, applications should change the |
| 2415 | * focus mode to other modes. |
| 2416 | * |
| 2417 | * @see #FOCUS_MODE_CONTINUOUS_PICTURE |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2418 | */ |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2419 | public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2420 | |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2421 | /** |
| 2422 | * Continuous auto focus mode intended for taking pictures. The camera |
| 2423 | * continuously tries to focus. The speed of focus change is more |
| 2424 | * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 2425 | * starts when the parameter is set. |
| 2426 | * |
Wu-cheng Li | 0f4f97b | 2011-10-27 18:07:01 +0800 | [diff] [blame] | 2427 | * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in |
| 2428 | * this mode. If the autofocus is in the middle of scanning, the focus |
| 2429 | * callback will return when it completes. If the autofocus is not |
| 2430 | * scanning, the focus callback will immediately return with a boolean |
| 2431 | * that indicates whether the focus is sharp or not. The apps can then |
| 2432 | * decide if they want to take a picture immediately or to change the |
| 2433 | * focus mode to auto, and run a full autofocus cycle. The focus |
| 2434 | * position is locked after autoFocus call. If applications want to |
| 2435 | * resume the continuous focus, cancelAutoFocus must be called. |
| 2436 | * Restarting the preview will not resume the continuous autofocus. To |
| 2437 | * stop continuous focus, applications should change the focus mode to |
| 2438 | * other modes. |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2439 | * |
| 2440 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2441 | */ |
| 2442 | public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture"; |
| 2443 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2444 | // Indices for focus distance array. |
| 2445 | /** |
| 2446 | * The array index of near focus distance for use with |
| 2447 | * {@link #getFocusDistances(float[])}. |
| 2448 | */ |
| 2449 | public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; |
| 2450 | |
| 2451 | /** |
| 2452 | * The array index of optimal focus distance for use with |
| 2453 | * {@link #getFocusDistances(float[])}. |
| 2454 | */ |
| 2455 | public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; |
| 2456 | |
| 2457 | /** |
| 2458 | * The array index of far focus distance for use with |
| 2459 | * {@link #getFocusDistances(float[])}. |
| 2460 | */ |
| 2461 | public static final int FOCUS_DISTANCE_FAR_INDEX = 2; |
| 2462 | |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 2463 | /** |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2464 | * The array index of minimum preview fps for use with {@link |
| 2465 | * #getPreviewFpsRange(int[])} or {@link |
| 2466 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2467 | */ |
| 2468 | public static final int PREVIEW_FPS_MIN_INDEX = 0; |
| 2469 | |
| 2470 | /** |
| 2471 | * The array index of maximum preview fps for use with {@link |
| 2472 | * #getPreviewFpsRange(int[])} or {@link |
| 2473 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2474 | */ |
| 2475 | public static final int PREVIEW_FPS_MAX_INDEX = 1; |
| 2476 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2477 | // Formats for setPreviewFormat and setPictureFormat. |
| 2478 | private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; |
| 2479 | private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2480 | private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 2481 | private static final String PIXEL_FORMAT_YUV420P = "yuv420p"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2482 | private static final String PIXEL_FORMAT_RGB565 = "rgb565"; |
| 2483 | private static final String PIXEL_FORMAT_JPEG = "jpeg"; |
Wu-cheng Li | 70fb908 | 2011-08-02 17:49:50 +0800 | [diff] [blame] | 2484 | private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2485 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2486 | /** |
| 2487 | * Order matters: Keys that are {@link #set(String, String) set} later |
| 2488 | * will take precedence over keys that are set earlier (if the two keys |
| 2489 | * conflict with each other). |
| 2490 | * |
| 2491 | * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it |
| 2492 | * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later |
| 2493 | * is the one that will take precedence. |
| 2494 | * </p> |
| 2495 | */ |
| 2496 | private final LinkedHashMap<String, String> mMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | |
| 2498 | private Parameters() { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2499 | mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2503 | * Overwrite existing parameters with a copy of the ones from {@code other}. |
| 2504 | * |
| 2505 | * <b>For use by the legacy shim only.</b> |
| 2506 | * |
| 2507 | * @hide |
| 2508 | */ |
| 2509 | public void copyFrom(Parameters other) { |
| 2510 | if (other == null) { |
| 2511 | throw new NullPointerException("other must not be null"); |
| 2512 | } |
| 2513 | |
| 2514 | mMap.putAll(other.mMap); |
| 2515 | } |
| 2516 | |
| 2517 | private Camera getOuter() { |
| 2518 | return Camera.this; |
| 2519 | } |
| 2520 | |
Ruben Brunk | d1f113d | 2014-07-11 11:46:20 -0700 | [diff] [blame] | 2521 | |
| 2522 | /** |
| 2523 | * Value equality check. |
| 2524 | * |
| 2525 | * @hide |
| 2526 | */ |
| 2527 | public boolean same(Parameters other) { |
| 2528 | if (this == other) { |
| 2529 | return true; |
| 2530 | } |
| 2531 | return other != null && Parameters.this.mMap.equals(other.mMap); |
| 2532 | } |
| 2533 | |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2534 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | * Writes the current Parameters to the log. |
| 2536 | * @hide |
| 2537 | * @deprecated |
| 2538 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 2539 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | public void dump() { |
| 2541 | Log.e(TAG, "dump: size=" + mMap.size()); |
| 2542 | for (String k : mMap.keySet()) { |
| 2543 | Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * Creates a single string with all the parameters set in |
| 2549 | * this Parameters object. |
| 2550 | * <p>The {@link #unflatten(String)} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2551 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | * @return a String with all values from this Parameters object, in |
| 2553 | * semi-colon delimited key-value pairs |
| 2554 | */ |
| 2555 | public String flatten() { |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 2556 | StringBuilder flattened = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | for (String k : mMap.keySet()) { |
| 2558 | flattened.append(k); |
| 2559 | flattened.append("="); |
| 2560 | flattened.append(mMap.get(k)); |
| 2561 | flattened.append(";"); |
| 2562 | } |
| 2563 | // chop off the extra semicolon at the end |
| 2564 | flattened.deleteCharAt(flattened.length()-1); |
| 2565 | return flattened.toString(); |
| 2566 | } |
| 2567 | |
| 2568 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2569 | * Takes a flattened string of parameters and adds each one to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2570 | * this Parameters object. |
| 2571 | * <p>The {@link #flatten()} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2572 | * |
| 2573 | * @param flattened a String of parameters (key-value paired) that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | * are semi-colon delimited |
| 2575 | */ |
| 2576 | public void unflatten(String flattened) { |
| 2577 | mMap.clear(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2578 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 2579 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); |
| 2580 | splitter.setString(flattened); |
| 2581 | for (String kv : splitter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | int pos = kv.indexOf('='); |
| 2583 | if (pos == -1) { |
| 2584 | continue; |
| 2585 | } |
| 2586 | String k = kv.substring(0, pos); |
| 2587 | String v = kv.substring(pos + 1); |
| 2588 | mMap.put(k, v); |
| 2589 | } |
| 2590 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2592 | public void remove(String key) { |
| 2593 | mMap.remove(key); |
| 2594 | } |
| 2595 | |
| 2596 | /** |
| 2597 | * Sets a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2598 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | * @param key the key name for the parameter |
| 2600 | * @param value the String value of the parameter |
| 2601 | */ |
| 2602 | public void set(String key, String value) { |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 2603 | if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) { |
| 2604 | Log.e(TAG, "Key \"" + key + "\" contains invalid character (= or ; or \\0)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | return; |
| 2606 | } |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 2607 | if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) { |
| 2608 | Log.e(TAG, "Value \"" + value + "\" contains invalid character (= or ; or \\0)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | return; |
| 2610 | } |
| 2611 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2612 | put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | /** |
| 2616 | * Sets an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2617 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | * @param key the key name for the parameter |
| 2619 | * @param value the int value of the parameter |
| 2620 | */ |
| 2621 | public void set(String key, int value) { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2622 | put(key, Integer.toString(value)); |
| 2623 | } |
| 2624 | |
| 2625 | private void put(String key, String value) { |
| 2626 | /* |
| 2627 | * Remove the key if it already exists. |
| 2628 | * |
| 2629 | * This way setting a new value for an already existing key will always move |
| 2630 | * that key to be ordered the latest in the map. |
| 2631 | */ |
| 2632 | mMap.remove(key); |
| 2633 | mMap.put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | } |
| 2635 | |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2636 | private void set(String key, List<Area> areas) { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 2637 | if (areas == null) { |
| 2638 | set(key, "(0,0,0,0,0)"); |
| 2639 | } else { |
| 2640 | StringBuilder buffer = new StringBuilder(); |
| 2641 | for (int i = 0; i < areas.size(); i++) { |
| 2642 | Area area = areas.get(i); |
| 2643 | Rect rect = area.rect; |
| 2644 | buffer.append('('); |
| 2645 | buffer.append(rect.left); |
| 2646 | buffer.append(','); |
| 2647 | buffer.append(rect.top); |
| 2648 | buffer.append(','); |
| 2649 | buffer.append(rect.right); |
| 2650 | buffer.append(','); |
| 2651 | buffer.append(rect.bottom); |
| 2652 | buffer.append(','); |
| 2653 | buffer.append(area.weight); |
| 2654 | buffer.append(')'); |
| 2655 | if (i != areas.size() - 1) buffer.append(','); |
| 2656 | } |
| 2657 | set(key, buffer.toString()); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2658 | } |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 2659 | } |
| 2660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | /** |
| 2662 | * Returns the value of a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2663 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | * @param key the key name for the parameter |
| 2665 | * @return the String value of the parameter |
| 2666 | */ |
| 2667 | public String get(String key) { |
| 2668 | return mMap.get(key); |
| 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * Returns the value of an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2673 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | * @param key the key name for the parameter |
| 2675 | * @return the int value of the parameter |
| 2676 | */ |
| 2677 | public int getInt(String key) { |
| 2678 | return Integer.parseInt(mMap.get(key)); |
| 2679 | } |
| 2680 | |
| 2681 | /** |
Wu-cheng Li | 26274fa | 2011-05-05 14:36:28 +0800 | [diff] [blame] | 2682 | * Sets the dimensions for preview pictures. If the preview has already |
| 2683 | * started, applications should stop the preview first before changing |
| 2684 | * preview size. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2685 | * |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2686 | * The sides of width and height are based on camera orientation. That |
| 2687 | * is, the preview size is the size before it is rotated by display |
| 2688 | * orientation. So applications need to consider the display orientation |
| 2689 | * while setting preview size. For example, suppose the camera supports |
| 2690 | * both 480x320 and 320x480 preview sizes. The application wants a 3:2 |
| 2691 | * preview ratio. If the display orientation is set to 0 or 180, preview |
| 2692 | * size should be set to 480x320. If the display orientation is set to |
| 2693 | * 90 or 270, preview size should be set to 320x480. The display |
| 2694 | * orientation should also be considered while setting picture size and |
| 2695 | * thumbnail size. |
| 2696 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | * @param width the width of the pictures, in pixels |
| 2698 | * @param height the height of the pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2699 | * @see #setDisplayOrientation(int) |
| 2700 | * @see #getCameraInfo(int, CameraInfo) |
| 2701 | * @see #setPictureSize(int, int) |
| 2702 | * @see #setJpegThumbnailSize(int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | */ |
| 2704 | public void setPreviewSize(int width, int height) { |
| 2705 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2706 | set(KEY_PREVIEW_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Returns the dimensions setting for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2711 | * |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2712 | * @return a Size object with the width and height setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | * for the preview picture |
| 2714 | */ |
| 2715 | public Size getPreviewSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2716 | String pair = get(KEY_PREVIEW_SIZE); |
| 2717 | return strToSize(pair); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2721 | * Gets the supported preview sizes. |
| 2722 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2723 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 2724 | * with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2725 | */ |
| 2726 | public List<Size> getSupportedPreviewSizes() { |
| 2727 | String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2728 | return splitSize(str); |
| 2729 | } |
| 2730 | |
| 2731 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2732 | * <p>Gets the supported video frame sizes that can be used by |
| 2733 | * MediaRecorder.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2734 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2735 | * <p>If the returned list is not null, the returned list will contain at |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2736 | * least one Size and one of the sizes in the returned list must be |
| 2737 | * passed to MediaRecorder.setVideoSize() for camcorder application if |
| 2738 | * camera is used as the video source. In this case, the size of the |
| 2739 | * preview can be different from the resolution of the recorded video |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2740 | * during video recording.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2741 | * |
| 2742 | * @return a list of Size object if camera has separate preview and |
| 2743 | * video output; otherwise, null is returned. |
| 2744 | * @see #getPreferredPreviewSizeForVideo() |
| 2745 | */ |
| 2746 | public List<Size> getSupportedVideoSizes() { |
| 2747 | String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2748 | return splitSize(str); |
| 2749 | } |
| 2750 | |
| 2751 | /** |
| 2752 | * Returns the preferred or recommended preview size (width and height) |
| 2753 | * in pixels for video recording. Camcorder applications should |
| 2754 | * set the preview size to a value that is not larger than the |
| 2755 | * preferred preview size. In other words, the product of the width |
| 2756 | * and height of the preview size should not be larger than that of |
| 2757 | * the preferred preview size. In addition, we recommend to choose a |
| 2758 | * preview size that has the same aspect ratio as the resolution of |
| 2759 | * video to be recorded. |
| 2760 | * |
| 2761 | * @return the preferred preview size (width and height) in pixels for |
| 2762 | * video recording if getSupportedVideoSizes() does not return |
| 2763 | * null; otherwise, null is returned. |
| 2764 | * @see #getSupportedVideoSizes() |
| 2765 | */ |
| 2766 | public Size getPreferredPreviewSizeForVideo() { |
| 2767 | String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); |
| 2768 | return strToSize(pair); |
| 2769 | } |
| 2770 | |
| 2771 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2772 | * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2773 | * applications set both width and height to 0, EXIF will not contain |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2774 | * thumbnail.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2775 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2776 | * <p>Applications need to consider the display orientation. See {@link |
| 2777 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2778 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2779 | * @param width the width of the thumbnail, in pixels |
| 2780 | * @param height the height of the thumbnail, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 2781 | * @see #setPreviewSize(int,int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2783 | public void setJpegThumbnailSize(int width, int height) { |
| 2784 | set(KEY_JPEG_THUMBNAIL_WIDTH, width); |
| 2785 | set(KEY_JPEG_THUMBNAIL_HEIGHT, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2789 | * Returns the dimensions for EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2791 | * @return a Size object with the height and width setting for the EXIF |
| 2792 | * thumbnails |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2794 | public Size getJpegThumbnailSize() { |
| 2795 | return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), |
| 2796 | getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2800 | * Gets the supported jpeg thumbnail sizes. |
| 2801 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2802 | * @return a list of Size object. This method will always return a list |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2803 | * with at least two elements. Size 0,0 (no thumbnail) is always |
| 2804 | * supported. |
| 2805 | */ |
| 2806 | public List<Size> getSupportedJpegThumbnailSizes() { |
| 2807 | String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 2808 | return splitSize(str); |
| 2809 | } |
| 2810 | |
| 2811 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2812 | * Sets the quality of the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2814 | * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 |
| 2815 | * to 100, with 100 being the best. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2817 | public void setJpegThumbnailQuality(int quality) { |
| 2818 | set(KEY_JPEG_THUMBNAIL_QUALITY, quality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2822 | * Returns the quality setting for the EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2824 | * @return the JPEG quality setting of the EXIF thumbnail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2826 | public int getJpegThumbnailQuality() { |
| 2827 | return getInt(KEY_JPEG_THUMBNAIL_QUALITY); |
| 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * Sets Jpeg quality of captured picture. |
| 2832 | * |
| 2833 | * @param quality the JPEG quality of captured picture. The range is 1 |
| 2834 | * to 100, with 100 being the best. |
| 2835 | */ |
| 2836 | public void setJpegQuality(int quality) { |
| 2837 | set(KEY_JPEG_QUALITY, quality); |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * Returns the quality setting for the JPEG picture. |
| 2842 | * |
| 2843 | * @return the JPEG picture quality setting. |
| 2844 | */ |
| 2845 | public int getJpegQuality() { |
| 2846 | return getInt(KEY_JPEG_QUALITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2850 | * Sets the rate at which preview frames are received. This is the |
| 2851 | * target frame rate. The actual frame rate depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2852 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | * @param fps the frame rate (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2854 | * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2856 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | public void setPreviewFrameRate(int fps) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2858 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 2862 | * Returns the setting for the rate at which preview frames are |
| 2863 | * received. This is the target frame rate. The actual frame rate |
| 2864 | * depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2865 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | * @return the frame rate setting (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2867 | * @deprecated replaced by {@link #getPreviewFpsRange(int[])} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2869 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | public int getPreviewFrameRate() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2871 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2875 | * Gets the supported preview frame rates. |
| 2876 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2877 | * @return a list of supported preview frame rates. null if preview |
| 2878 | * frame rate setting is not supported. |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2879 | * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2880 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2881 | @Deprecated |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2882 | public List<Integer> getSupportedPreviewFrameRates() { |
| 2883 | String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 2884 | return splitInt(str); |
| 2885 | } |
| 2886 | |
| 2887 | /** |
Hai Guo | 4a68e3c | 2012-12-05 21:50:28 +0800 | [diff] [blame] | 2888 | * Sets the minimum and maximum preview fps. This controls the rate of |
Wu-cheng Li | 1620d11 | 2010-08-27 15:09:20 -0700 | [diff] [blame] | 2889 | * preview frames received in {@link PreviewCallback}. The minimum and |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2890 | * maximum preview fps must be one of the elements from {@link |
| 2891 | * #getSupportedPreviewFpsRange}. |
| 2892 | * |
| 2893 | * @param min the minimum preview fps (scaled by 1000). |
| 2894 | * @param max the maximum preview fps (scaled by 1000). |
| 2895 | * @throws RuntimeException if fps range is invalid. |
| 2896 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 2897 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2898 | */ |
| 2899 | public void setPreviewFpsRange(int min, int max) { |
| 2900 | set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); |
| 2901 | } |
| 2902 | |
| 2903 | /** |
| 2904 | * Returns the current minimum and maximum preview fps. The values are |
| 2905 | * one of the elements returned by {@link #getSupportedPreviewFpsRange}. |
| 2906 | * |
| 2907 | * @return range the minimum and maximum preview fps (scaled by 1000). |
| 2908 | * @see #PREVIEW_FPS_MIN_INDEX |
| 2909 | * @see #PREVIEW_FPS_MAX_INDEX |
| 2910 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2911 | */ |
| 2912 | public void getPreviewFpsRange(int[] range) { |
| 2913 | if (range == null || range.length != 2) { |
| 2914 | throw new IllegalArgumentException( |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 2915 | "range must be an array with two elements."); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2916 | } |
| 2917 | splitInt(get(KEY_PREVIEW_FPS_RANGE), range); |
| 2918 | } |
| 2919 | |
| 2920 | /** |
| 2921 | * Gets the supported preview fps (frame-per-second) ranges. Each range |
| 2922 | * contains a minimum fps and maximum fps. If minimum fps equals to |
| 2923 | * maximum fps, the camera outputs frames in fixed frame rate. If not, |
| 2924 | * the camera outputs frames in auto frame rate. The actual frame rate |
| 2925 | * fluctuates between the minimum and the maximum. The values are |
| 2926 | * multiplied by 1000 and represented in integers. For example, if frame |
| 2927 | * rate is 26.623 frames per second, the value is 26623. |
| 2928 | * |
| 2929 | * @return a list of supported preview fps ranges. This method returns a |
| 2930 | * list with at least one element. Every element is an int array |
| 2931 | * of two values - minimum fps and maximum fps. The list is |
| 2932 | * sorted from small to large (first by maximum fps and then |
| 2933 | * minimum fps). |
| 2934 | * @see #PREVIEW_FPS_MIN_INDEX |
| 2935 | * @see #PREVIEW_FPS_MAX_INDEX |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2936 | */ |
| 2937 | public List<int[]> getSupportedPreviewFpsRange() { |
| 2938 | String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); |
| 2939 | return splitRange(str); |
| 2940 | } |
| 2941 | |
| 2942 | /** |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 2943 | * Sets the image format for preview pictures. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 2944 | * <p>If this is never called, the default format will be |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2945 | * {@link android.graphics.ImageFormat#NV21}, which |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 2946 | * uses the NV21 encoding format.</p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 2947 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 2948 | * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of |
| 2949 | * the available preview formats. |
| 2950 | * |
| 2951 | * <p>It is strongly recommended that either |
| 2952 | * {@link android.graphics.ImageFormat#NV21} or |
| 2953 | * {@link android.graphics.ImageFormat#YV12} is used, since |
| 2954 | * they are supported by all camera devices.</p> |
| 2955 | * |
| 2956 | * <p>For YV12, the image buffer that is received is not necessarily |
| 2957 | * tightly packed, as there may be padding at the end of each row of |
| 2958 | * pixel data, as described in |
| 2959 | * {@link android.graphics.ImageFormat#YV12}. For camera callback data, |
| 2960 | * it can be assumed that the stride of the Y and UV data is the |
| 2961 | * smallest possible that meets the alignment requirements. That is, if |
| 2962 | * the preview size is <var>width x height</var>, then the following |
| 2963 | * equations describe the buffer index for the beginning of row |
| 2964 | * <var>y</var> for the Y plane and row <var>c</var> for the U and V |
| 2965 | * planes: |
| 2966 | * |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 2967 | * <pre>{@code |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 2968 | * yStride = (int) ceil(width / 16.0) * 16; |
| 2969 | * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16; |
| 2970 | * ySize = yStride * height; |
| 2971 | * uvSize = uvStride * height / 2; |
| 2972 | * yRowIndex = yStride * y; |
| 2973 | * uRowIndex = ySize + uvSize + uvStride * c; |
| 2974 | * vRowIndex = ySize + uvStride * c; |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 2975 | * size = ySize + uvSize * 2; |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 2976 | * } |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 2977 | *</pre> |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 2978 | * |
| 2979 | * @param pixel_format the desired preview picture format, defined by |
| 2980 | * one of the {@link android.graphics.ImageFormat} constants. (E.g., |
| 2981 | * <var>ImageFormat.NV21</var> (default), or |
| 2982 | * <var>ImageFormat.YV12</var>) |
| 2983 | * |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 2984 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 2985 | * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | */ |
| 2987 | public void setPreviewFormat(int pixel_format) { |
| 2988 | String s = cameraFormatForPixelFormat(pixel_format); |
| 2989 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2990 | throw new IllegalArgumentException( |
| 2991 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | } |
| 2993 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2994 | set(KEY_PREVIEW_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 2998 | * Returns the image format for preview frames got from |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2999 | * {@link PreviewCallback}. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3000 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3001 | * @return the preview format. |
| 3002 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3003 | * @see #setPreviewFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3004 | */ |
| 3005 | public int getPreviewFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3006 | return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); |
| 3007 | } |
| 3008 | |
| 3009 | /** |
Wu-cheng Li | f9293e7 | 2011-02-25 13:35:10 +0800 | [diff] [blame] | 3010 | * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} |
| 3011 | * is always supported. {@link android.graphics.ImageFormat#YV12} |
| 3012 | * is always supported since API level 12. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3013 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3014 | * @return a list of supported preview formats. This method will always |
| 3015 | * return a list with at least one element. |
| 3016 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3017 | * @see #setPreviewFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3018 | */ |
| 3019 | public List<Integer> getSupportedPreviewFormats() { |
| 3020 | String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3021 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3022 | for (String s : split(str)) { |
| 3023 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3024 | if (f == ImageFormat.UNKNOWN) continue; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3025 | formats.add(f); |
| 3026 | } |
| 3027 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3031 | * <p>Sets the dimensions for pictures.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3032 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3033 | * <p>Applications need to consider the display orientation. See {@link |
| 3034 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | * @param width the width for pictures, in pixels |
| 3037 | * @param height the height for pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3038 | * @see #setPreviewSize(int,int) |
| 3039 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | */ |
| 3041 | public void setPictureSize(int width, int height) { |
| 3042 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3043 | set(KEY_PICTURE_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * Returns the dimension setting for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3048 | * |
| 3049 | * @return a Size object with the height and width setting |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3050 | * for pictures |
| 3051 | */ |
| 3052 | public Size getPictureSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3053 | String pair = get(KEY_PICTURE_SIZE); |
| 3054 | return strToSize(pair); |
| 3055 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3057 | /** |
| 3058 | * Gets the supported picture sizes. |
| 3059 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3060 | * @return a list of supported picture sizes. This method will always |
| 3061 | * return a list with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3062 | */ |
| 3063 | public List<Size> getSupportedPictureSizes() { |
| 3064 | String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3065 | return splitSize(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | /** |
| 3069 | * Sets the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3070 | * |
| 3071 | * @param pixel_format the desired picture format |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3072 | * (<var>ImageFormat.NV21</var>, |
| 3073 | * <var>ImageFormat.RGB_565</var>, or |
| 3074 | * <var>ImageFormat.JPEG</var>) |
| 3075 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3076 | */ |
| 3077 | public void setPictureFormat(int pixel_format) { |
| 3078 | String s = cameraFormatForPixelFormat(pixel_format); |
| 3079 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3080 | throw new IllegalArgumentException( |
| 3081 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3082 | } |
| 3083 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3084 | set(KEY_PICTURE_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | /** |
| 3088 | * Returns the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3089 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3090 | * @return the picture format |
| 3091 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | */ |
| 3093 | public int getPictureFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3094 | return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); |
| 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * Gets the supported picture formats. |
| 3099 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3100 | * @return supported picture formats. This method will always return a |
| 3101 | * list with at least one element. |
| 3102 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3103 | */ |
| 3104 | public List<Integer> getSupportedPictureFormats() { |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3105 | String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); |
| 3106 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3107 | for (String s : split(str)) { |
| 3108 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3109 | if (f == ImageFormat.UNKNOWN) continue; |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3110 | formats.add(f); |
| 3111 | } |
| 3112 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | private String cameraFormatForPixelFormat(int pixel_format) { |
| 3116 | switch(pixel_format) { |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3117 | case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; |
| 3118 | case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; |
| 3119 | case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3120 | case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3121 | case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; |
| 3122 | case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; |
| 3123 | default: return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | private int pixelFormatForCameraFormat(String format) { |
| 3128 | if (format == null) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3129 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3131 | if (format.equals(PIXEL_FORMAT_YUV422SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3132 | return ImageFormat.NV16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3133 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3134 | if (format.equals(PIXEL_FORMAT_YUV420SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3135 | return ImageFormat.NV21; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3137 | if (format.equals(PIXEL_FORMAT_YUV422I)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3138 | return ImageFormat.YUY2; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3139 | |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3140 | if (format.equals(PIXEL_FORMAT_YUV420P)) |
| 3141 | return ImageFormat.YV12; |
| 3142 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3143 | if (format.equals(PIXEL_FORMAT_RGB565)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3144 | return ImageFormat.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3146 | if (format.equals(PIXEL_FORMAT_JPEG)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3147 | return ImageFormat.JPEG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3149 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | } |
| 3151 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3152 | /** |
Wu-cheng Li | 8969ea1 | 2012-04-20 17:38:09 +0800 | [diff] [blame] | 3153 | * Sets the clockwise rotation angle in degrees relative to the |
| 3154 | * orientation of the camera. This affects the pictures returned from |
| 3155 | * JPEG {@link PictureCallback}. The camera driver may set orientation |
| 3156 | * in the EXIF header without rotating the picture. Or the driver may |
| 3157 | * rotate the picture and the EXIF thumbnail. If the Jpeg picture is |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3158 | * rotated, the orientation in the EXIF header will be missing or 1 (row |
| 3159 | * #0 is top and column #0 is left side). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3160 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3161 | * <p> |
| 3162 | * If applications want to rotate the picture to match the orientation |
| 3163 | * of what users see, apps should use |
| 3164 | * {@link android.view.OrientationEventListener} and |
| 3165 | * {@link android.hardware.Camera.CameraInfo}. The value from |
| 3166 | * OrientationEventListener is relative to the natural orientation of |
| 3167 | * the device. CameraInfo.orientation is the angle between camera |
| 3168 | * orientation and natural device orientation. The sum of the two is the |
| 3169 | * rotation angle for back-facing camera. The difference of the two is |
| 3170 | * the rotation angle for front-facing camera. Note that the JPEG |
| 3171 | * pictures of front-facing cameras are not mirrored as in preview |
| 3172 | * display. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3173 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3174 | * <p> |
| 3175 | * For example, suppose the natural orientation of the device is |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3176 | * portrait. The device is rotated 270 degrees clockwise, so the device |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3177 | * orientation is 270. Suppose a back-facing camera sensor is mounted in |
| 3178 | * landscape and the top side of the camera sensor is aligned with the |
| 3179 | * right edge of the display in natural orientation. So the camera |
| 3180 | * orientation is 90. The rotation should be set to 0 (270 + 90). |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3181 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 3182 | * <p>The reference code is as follows. |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3183 | * |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3184 | * <pre> |
Scott Main | 9a10bf0 | 2011-08-24 19:09:48 -0700 | [diff] [blame] | 3185 | * public void onOrientationChanged(int orientation) { |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3186 | * if (orientation == ORIENTATION_UNKNOWN) return; |
| 3187 | * android.hardware.Camera.CameraInfo info = |
| 3188 | * new android.hardware.Camera.CameraInfo(); |
| 3189 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 3190 | * orientation = (orientation + 45) / 90 * 90; |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3191 | * int rotation = 0; |
| 3192 | * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { |
| 3193 | * rotation = (info.orientation - orientation + 360) % 360; |
| 3194 | * } else { // back-facing camera |
| 3195 | * rotation = (info.orientation + orientation) % 360; |
| 3196 | * } |
| 3197 | * mParameters.setRotation(rotation); |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3198 | * } |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3199 | * </pre> |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3200 | * |
| 3201 | * @param rotation The rotation angle in degrees relative to the |
| 3202 | * orientation of the camera. Rotation can only be 0, |
| 3203 | * 90, 180 or 270. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3204 | * @throws IllegalArgumentException if rotation value is invalid. |
| 3205 | * @see android.view.OrientationEventListener |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3206 | * @see #getCameraInfo(int, CameraInfo) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3207 | */ |
| 3208 | public void setRotation(int rotation) { |
| 3209 | if (rotation == 0 || rotation == 90 || rotation == 180 |
| 3210 | || rotation == 270) { |
| 3211 | set(KEY_ROTATION, Integer.toString(rotation)); |
| 3212 | } else { |
| 3213 | throw new IllegalArgumentException( |
| 3214 | "Invalid rotation=" + rotation); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | /** |
| 3219 | * Sets GPS latitude coordinate. This will be stored in JPEG EXIF |
| 3220 | * header. |
| 3221 | * |
| 3222 | * @param latitude GPS latitude coordinate. |
| 3223 | */ |
| 3224 | public void setGpsLatitude(double latitude) { |
| 3225 | set(KEY_GPS_LATITUDE, Double.toString(latitude)); |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * Sets GPS longitude coordinate. This will be stored in JPEG EXIF |
| 3230 | * header. |
| 3231 | * |
| 3232 | * @param longitude GPS longitude coordinate. |
| 3233 | */ |
| 3234 | public void setGpsLongitude(double longitude) { |
| 3235 | set(KEY_GPS_LONGITUDE, Double.toString(longitude)); |
| 3236 | } |
| 3237 | |
| 3238 | /** |
| 3239 | * Sets GPS altitude. This will be stored in JPEG EXIF header. |
| 3240 | * |
| 3241 | * @param altitude GPS altitude in meters. |
| 3242 | */ |
| 3243 | public void setGpsAltitude(double altitude) { |
| 3244 | set(KEY_GPS_ALTITUDE, Double.toString(altitude)); |
| 3245 | } |
| 3246 | |
| 3247 | /** |
| 3248 | * Sets GPS timestamp. This will be stored in JPEG EXIF header. |
| 3249 | * |
| 3250 | * @param timestamp GPS timestamp (UTC in seconds since January 1, |
| 3251 | * 1970). |
| 3252 | */ |
| 3253 | public void setGpsTimestamp(long timestamp) { |
| 3254 | set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); |
| 3255 | } |
| 3256 | |
| 3257 | /** |
Eino-Ville Talvala | d840727 | 2015-11-08 18:27:20 -0800 | [diff] [blame] | 3258 | * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes |
| 3259 | * long, in the JPEG EXIF header. |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3260 | * |
| 3261 | * @param processing_method The processing method to get this location. |
| 3262 | */ |
| 3263 | public void setGpsProcessingMethod(String processing_method) { |
| 3264 | set(KEY_GPS_PROCESSING_METHOD, processing_method); |
| 3265 | } |
| 3266 | |
| 3267 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3268 | * Removes GPS latitude, longitude, altitude, and timestamp from the |
| 3269 | * parameters. |
| 3270 | */ |
| 3271 | public void removeGpsData() { |
| 3272 | remove(KEY_GPS_LATITUDE); |
| 3273 | remove(KEY_GPS_LONGITUDE); |
| 3274 | remove(KEY_GPS_ALTITUDE); |
| 3275 | remove(KEY_GPS_TIMESTAMP); |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3276 | remove(KEY_GPS_PROCESSING_METHOD); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | /** |
| 3280 | * Gets the current white balance setting. |
| 3281 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3282 | * @return current white balance. null if white balance setting is not |
| 3283 | * supported. |
| 3284 | * @see #WHITE_BALANCE_AUTO |
| 3285 | * @see #WHITE_BALANCE_INCANDESCENT |
| 3286 | * @see #WHITE_BALANCE_FLUORESCENT |
| 3287 | * @see #WHITE_BALANCE_WARM_FLUORESCENT |
| 3288 | * @see #WHITE_BALANCE_DAYLIGHT |
| 3289 | * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT |
| 3290 | * @see #WHITE_BALANCE_TWILIGHT |
| 3291 | * @see #WHITE_BALANCE_SHADE |
| 3292 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3293 | */ |
| 3294 | public String getWhiteBalance() { |
| 3295 | return get(KEY_WHITE_BALANCE); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3299 | * Sets the white balance. Changing the setting will release the |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3300 | * auto-white balance lock. It is recommended not to change white |
| 3301 | * balance and AWB lock at the same time. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3302 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3303 | * @param value new white balance. |
| 3304 | * @see #getWhiteBalance() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3305 | * @see #setAutoWhiteBalanceLock(boolean) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3306 | */ |
| 3307 | public void setWhiteBalance(String value) { |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3308 | String oldValue = get(KEY_WHITE_BALANCE); |
| 3309 | if (same(value, oldValue)) return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3310 | set(KEY_WHITE_BALANCE, value); |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3311 | set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | /** |
| 3315 | * Gets the supported white balance. |
| 3316 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3317 | * @return a list of supported white balance. null if white balance |
| 3318 | * setting is not supported. |
| 3319 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3320 | */ |
| 3321 | public List<String> getSupportedWhiteBalance() { |
| 3322 | String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); |
| 3323 | return split(str); |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Gets the current color effect setting. |
| 3328 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3329 | * @return current color effect. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3330 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3331 | * @see #EFFECT_NONE |
| 3332 | * @see #EFFECT_MONO |
| 3333 | * @see #EFFECT_NEGATIVE |
| 3334 | * @see #EFFECT_SOLARIZE |
| 3335 | * @see #EFFECT_SEPIA |
| 3336 | * @see #EFFECT_POSTERIZE |
| 3337 | * @see #EFFECT_WHITEBOARD |
| 3338 | * @see #EFFECT_BLACKBOARD |
| 3339 | * @see #EFFECT_AQUA |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3340 | */ |
| 3341 | public String getColorEffect() { |
| 3342 | return get(KEY_EFFECT); |
| 3343 | } |
| 3344 | |
| 3345 | /** |
| 3346 | * Sets the current color effect setting. |
| 3347 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3348 | * @param value new color effect. |
| 3349 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3350 | */ |
| 3351 | public void setColorEffect(String value) { |
| 3352 | set(KEY_EFFECT, value); |
| 3353 | } |
| 3354 | |
| 3355 | /** |
| 3356 | * Gets the supported color effects. |
| 3357 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3358 | * @return a list of supported color effects. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3359 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3360 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3361 | */ |
| 3362 | public List<String> getSupportedColorEffects() { |
| 3363 | String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); |
| 3364 | return split(str); |
| 3365 | } |
| 3366 | |
| 3367 | |
| 3368 | /** |
| 3369 | * Gets the current antibanding setting. |
| 3370 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3371 | * @return current antibanding. null if antibanding setting is not |
| 3372 | * supported. |
| 3373 | * @see #ANTIBANDING_AUTO |
| 3374 | * @see #ANTIBANDING_50HZ |
| 3375 | * @see #ANTIBANDING_60HZ |
| 3376 | * @see #ANTIBANDING_OFF |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3377 | */ |
| 3378 | public String getAntibanding() { |
| 3379 | return get(KEY_ANTIBANDING); |
| 3380 | } |
| 3381 | |
| 3382 | /** |
| 3383 | * Sets the antibanding. |
| 3384 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3385 | * @param antibanding new antibanding value. |
| 3386 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3387 | */ |
| 3388 | public void setAntibanding(String antibanding) { |
| 3389 | set(KEY_ANTIBANDING, antibanding); |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * Gets the supported antibanding values. |
| 3394 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3395 | * @return a list of supported antibanding values. null if antibanding |
| 3396 | * setting is not supported. |
| 3397 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3398 | */ |
| 3399 | public List<String> getSupportedAntibanding() { |
| 3400 | String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); |
| 3401 | return split(str); |
| 3402 | } |
| 3403 | |
| 3404 | /** |
| 3405 | * Gets the current scene mode setting. |
| 3406 | * |
| 3407 | * @return one of SCENE_MODE_XXX string constant. null if scene mode |
| 3408 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3409 | * @see #SCENE_MODE_AUTO |
| 3410 | * @see #SCENE_MODE_ACTION |
| 3411 | * @see #SCENE_MODE_PORTRAIT |
| 3412 | * @see #SCENE_MODE_LANDSCAPE |
| 3413 | * @see #SCENE_MODE_NIGHT |
| 3414 | * @see #SCENE_MODE_NIGHT_PORTRAIT |
| 3415 | * @see #SCENE_MODE_THEATRE |
| 3416 | * @see #SCENE_MODE_BEACH |
| 3417 | * @see #SCENE_MODE_SNOW |
| 3418 | * @see #SCENE_MODE_SUNSET |
| 3419 | * @see #SCENE_MODE_STEADYPHOTO |
| 3420 | * @see #SCENE_MODE_FIREWORKS |
| 3421 | * @see #SCENE_MODE_SPORTS |
| 3422 | * @see #SCENE_MODE_PARTY |
| 3423 | * @see #SCENE_MODE_CANDLELIGHT |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 3424 | * @see #SCENE_MODE_BARCODE |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3425 | */ |
| 3426 | public String getSceneMode() { |
| 3427 | return get(KEY_SCENE_MODE); |
| 3428 | } |
| 3429 | |
| 3430 | /** |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 3431 | * Sets the scene mode. Changing scene mode may override other |
| 3432 | * parameters (such as flash mode, focus mode, white balance). For |
| 3433 | * example, suppose originally flash mode is on and supported flash |
| 3434 | * modes are on/off. In night scene mode, both flash mode and supported |
| 3435 | * flash mode may be changed to off. After setting scene mode, |
Wu-cheng Li | 2988ab7 | 2009-09-30 17:08:19 -0700 | [diff] [blame] | 3436 | * applications should call getParameters to know if some parameters are |
| 3437 | * changed. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3438 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3439 | * @param value scene mode. |
| 3440 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3441 | */ |
| 3442 | public void setSceneMode(String value) { |
| 3443 | set(KEY_SCENE_MODE, value); |
| 3444 | } |
| 3445 | |
| 3446 | /** |
| 3447 | * Gets the supported scene modes. |
| 3448 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3449 | * @return a list of supported scene modes. null if scene mode setting |
| 3450 | * is not supported. |
| 3451 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3452 | */ |
| 3453 | public List<String> getSupportedSceneModes() { |
| 3454 | String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3455 | return split(str); |
| 3456 | } |
| 3457 | |
| 3458 | /** |
| 3459 | * Gets the current flash mode setting. |
| 3460 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3461 | * @return current flash mode. null if flash mode setting is not |
| 3462 | * supported. |
| 3463 | * @see #FLASH_MODE_OFF |
| 3464 | * @see #FLASH_MODE_AUTO |
| 3465 | * @see #FLASH_MODE_ON |
| 3466 | * @see #FLASH_MODE_RED_EYE |
| 3467 | * @see #FLASH_MODE_TORCH |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3468 | */ |
| 3469 | public String getFlashMode() { |
| 3470 | return get(KEY_FLASH_MODE); |
| 3471 | } |
| 3472 | |
| 3473 | /** |
| 3474 | * Sets the flash mode. |
| 3475 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3476 | * @param value flash mode. |
| 3477 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3478 | */ |
| 3479 | public void setFlashMode(String value) { |
| 3480 | set(KEY_FLASH_MODE, value); |
| 3481 | } |
| 3482 | |
| 3483 | /** |
| 3484 | * Gets the supported flash modes. |
| 3485 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3486 | * @return a list of supported flash modes. null if flash mode setting |
| 3487 | * is not supported. |
| 3488 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3489 | */ |
| 3490 | public List<String> getSupportedFlashModes() { |
| 3491 | String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3492 | return split(str); |
| 3493 | } |
| 3494 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3495 | /** |
| 3496 | * Gets the current focus mode setting. |
| 3497 | * |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3498 | * @return current focus mode. This method will always return a non-null |
| 3499 | * value. Applications should call {@link |
| 3500 | * #autoFocus(AutoFocusCallback)} to start the focus if focus |
| 3501 | * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3502 | * @see #FOCUS_MODE_AUTO |
| 3503 | * @see #FOCUS_MODE_INFINITY |
| 3504 | * @see #FOCUS_MODE_MACRO |
| 3505 | * @see #FOCUS_MODE_FIXED |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 3506 | * @see #FOCUS_MODE_EDOF |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3507 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3508 | */ |
| 3509 | public String getFocusMode() { |
| 3510 | return get(KEY_FOCUS_MODE); |
| 3511 | } |
| 3512 | |
| 3513 | /** |
| 3514 | * Sets the focus mode. |
| 3515 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3516 | * @param value focus mode. |
| 3517 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3518 | */ |
| 3519 | public void setFocusMode(String value) { |
| 3520 | set(KEY_FOCUS_MODE, value); |
| 3521 | } |
| 3522 | |
| 3523 | /** |
| 3524 | * Gets the supported focus modes. |
| 3525 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3526 | * @return a list of supported focus modes. This method will always |
| 3527 | * return a list with at least one element. |
| 3528 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3529 | */ |
| 3530 | public List<String> getSupportedFocusModes() { |
| 3531 | String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3532 | return split(str); |
| 3533 | } |
| 3534 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3535 | /** |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3536 | * Gets the focal length (in millimeter) of the camera. |
| 3537 | * |
| 3538 | * @return the focal length. This method will always return a valid |
| 3539 | * value. |
| 3540 | */ |
| 3541 | public float getFocalLength() { |
| 3542 | return Float.parseFloat(get(KEY_FOCAL_LENGTH)); |
| 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * Gets the horizontal angle of view in degrees. |
| 3547 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame^] | 3548 | * @return horizontal angle of view. Returns -1.0 when the device |
| 3549 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3550 | */ |
| 3551 | public float getHorizontalViewAngle() { |
| 3552 | return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); |
| 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * Gets the vertical angle of view in degrees. |
| 3557 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame^] | 3558 | * @return vertical angle of view. Returns -1.0 when the device |
| 3559 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3560 | */ |
| 3561 | public float getVerticalViewAngle() { |
| 3562 | return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); |
| 3563 | } |
| 3564 | |
| 3565 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3566 | * Gets the current exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3567 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3568 | * @return current exposure compensation index. The range is {@link |
| 3569 | * #getMinExposureCompensation} to {@link |
| 3570 | * #getMaxExposureCompensation}. 0 means exposure is not |
| 3571 | * adjusted. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3572 | */ |
| 3573 | public int getExposureCompensation() { |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3574 | return getInt(KEY_EXPOSURE_COMPENSATION, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3578 | * Sets the exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3579 | * |
Wu-cheng Li | 0402e7d | 2010-02-26 15:04:55 +0800 | [diff] [blame] | 3580 | * @param value exposure compensation index. The valid value range is |
| 3581 | * from {@link #getMinExposureCompensation} (inclusive) to {@link |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3582 | * #getMaxExposureCompensation} (inclusive). 0 means exposure is |
| 3583 | * not adjusted. Application should call |
| 3584 | * getMinExposureCompensation and getMaxExposureCompensation to |
| 3585 | * know if exposure compensation is supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3586 | */ |
| 3587 | public void setExposureCompensation(int value) { |
| 3588 | set(KEY_EXPOSURE_COMPENSATION, value); |
| 3589 | } |
| 3590 | |
| 3591 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3592 | * Gets the maximum exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3593 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3594 | * @return maximum exposure compensation index (>=0). If both this |
| 3595 | * method and {@link #getMinExposureCompensation} return 0, |
| 3596 | * exposure compensation is not supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3597 | */ |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 3598 | public int getMaxExposureCompensation() { |
| 3599 | return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); |
| 3600 | } |
| 3601 | |
| 3602 | /** |
| 3603 | * Gets the minimum exposure compensation index. |
| 3604 | * |
| 3605 | * @return minimum exposure compensation index (<=0). If both this |
| 3606 | * method and {@link #getMaxExposureCompensation} return 0, |
| 3607 | * exposure compensation is not supported. |
| 3608 | */ |
| 3609 | public int getMinExposureCompensation() { |
| 3610 | return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); |
| 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * Gets the exposure compensation step. |
| 3615 | * |
| 3616 | * @return exposure compensation step. Applications can get EV by |
| 3617 | * multiplying the exposure compensation index and step. Ex: if |
| 3618 | * exposure compensation index is -6 and step is 0.333333333, EV |
| 3619 | * is -2. |
| 3620 | */ |
| 3621 | public float getExposureCompensationStep() { |
| 3622 | return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3626 | * <p>Sets the auto-exposure lock state. Applications should check |
| 3627 | * {@link #isAutoExposureLockSupported} before using this method.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3628 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3629 | * <p>If set to true, the camera auto-exposure routine will immediately |
| 3630 | * pause until the lock is set to false. Exposure compensation settings |
| 3631 | * changes will still take effect while auto-exposure is locked.</p> |
| 3632 | * |
| 3633 | * <p>If auto-exposure is already locked, setting this to true again has |
| 3634 | * no effect (the driver will not recalculate exposure values).</p> |
| 3635 | * |
| 3636 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 3637 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3638 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 3639 | * lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3640 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3641 | * <p>Exposure compensation, auto-exposure lock, and auto-white balance |
| 3642 | * lock can be used to capture an exposure-bracketed burst of images, |
| 3643 | * for example.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3644 | * |
| 3645 | * <p>Auto-exposure state, including the lock state, will not be |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3646 | * maintained after camera {@link #release()} is called. Locking |
| 3647 | * auto-exposure after {@link #open()} but before the first call to |
| 3648 | * {@link #startPreview()} will not allow the auto-exposure routine to |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3649 | * run at all, and may result in severely over- or under-exposed |
| 3650 | * images.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3651 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3652 | * @param toggle new state of the auto-exposure lock. True means that |
| 3653 | * auto-exposure is locked, false means that the auto-exposure |
| 3654 | * routine is free to run normally. |
| 3655 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3656 | * @see #getAutoExposureLock() |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3657 | */ |
| 3658 | public void setAutoExposureLock(boolean toggle) { |
| 3659 | set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); |
| 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * Gets the state of the auto-exposure lock. Applications should check |
| 3664 | * {@link #isAutoExposureLockSupported} before using this method. See |
| 3665 | * {@link #setAutoExposureLock} for details about the lock. |
| 3666 | * |
| 3667 | * @return State of the auto-exposure lock. Returns true if |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3668 | * auto-exposure is currently locked, and false otherwise. |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3669 | * |
| 3670 | * @see #setAutoExposureLock(boolean) |
| 3671 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3672 | */ |
| 3673 | public boolean getAutoExposureLock() { |
| 3674 | String str = get(KEY_AUTO_EXPOSURE_LOCK); |
| 3675 | return TRUE.equals(str); |
| 3676 | } |
| 3677 | |
| 3678 | /** |
| 3679 | * Returns true if auto-exposure locking is supported. Applications |
| 3680 | * should call this before trying to lock auto-exposure. See |
| 3681 | * {@link #setAutoExposureLock} for details about the lock. |
| 3682 | * |
| 3683 | * @return true if auto-exposure lock is supported. |
| 3684 | * @see #setAutoExposureLock(boolean) |
| 3685 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 3686 | */ |
| 3687 | public boolean isAutoExposureLockSupported() { |
| 3688 | String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); |
| 3689 | return TRUE.equals(str); |
| 3690 | } |
| 3691 | |
| 3692 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3693 | * <p>Sets the auto-white balance lock state. Applications should check |
| 3694 | * {@link #isAutoWhiteBalanceLockSupported} before using this |
| 3695 | * method.</p> |
| 3696 | * |
| 3697 | * <p>If set to true, the camera auto-white balance routine will |
| 3698 | * immediately pause until the lock is set to false.</p> |
| 3699 | * |
| 3700 | * <p>If auto-white balance is already locked, setting this to true |
| 3701 | * again has no effect (the driver will not recalculate white balance |
| 3702 | * values).</p> |
| 3703 | * |
| 3704 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 3705 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3706 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 3707 | * the lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3708 | * |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3709 | * <p> Changing the white balance mode with {@link #setWhiteBalance} |
| 3710 | * will release the auto-white balance lock if it is set.</p> |
| 3711 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3712 | * <p>Exposure compensation, AE lock, and AWB lock can be used to |
| 3713 | * capture an exposure-bracketed burst of images, for example. |
| 3714 | * Auto-white balance state, including the lock state, will not be |
| 3715 | * maintained after camera {@link #release()} is called. Locking |
| 3716 | * auto-white balance after {@link #open()} but before the first call to |
| 3717 | * {@link #startPreview()} will not allow the auto-white balance routine |
| 3718 | * to run at all, and may result in severely incorrect color in captured |
| 3719 | * images.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3720 | * |
| 3721 | * @param toggle new state of the auto-white balance lock. True means |
| 3722 | * that auto-white balance is locked, false means that the |
| 3723 | * auto-white balance routine is free to run normally. |
| 3724 | * |
| 3725 | * @see #getAutoWhiteBalanceLock() |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3726 | * @see #setWhiteBalance(String) |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3727 | */ |
| 3728 | public void setAutoWhiteBalanceLock(boolean toggle) { |
| 3729 | set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); |
| 3730 | } |
| 3731 | |
| 3732 | /** |
| 3733 | * Gets the state of the auto-white balance lock. Applications should |
| 3734 | * check {@link #isAutoWhiteBalanceLockSupported} before using this |
| 3735 | * method. See {@link #setAutoWhiteBalanceLock} for details about the |
| 3736 | * lock. |
| 3737 | * |
| 3738 | * @return State of the auto-white balance lock. Returns true if |
| 3739 | * auto-white balance is currently locked, and false |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 3740 | * otherwise. |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3741 | * |
| 3742 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3743 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3744 | */ |
| 3745 | public boolean getAutoWhiteBalanceLock() { |
| 3746 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK); |
| 3747 | return TRUE.equals(str); |
| 3748 | } |
| 3749 | |
| 3750 | /** |
| 3751 | * Returns true if auto-white balance locking is supported. Applications |
| 3752 | * should call this before trying to lock auto-white balance. See |
| 3753 | * {@link #setAutoWhiteBalanceLock} for details about the lock. |
| 3754 | * |
| 3755 | * @return true if auto-white balance lock is supported. |
| 3756 | * @see #setAutoWhiteBalanceLock(boolean) |
| 3757 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 3758 | */ |
| 3759 | public boolean isAutoWhiteBalanceLockSupported() { |
| 3760 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); |
| 3761 | return TRUE.equals(str); |
| 3762 | } |
| 3763 | |
| 3764 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3765 | * Gets current zoom value. This also works when smooth zoom is in |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3766 | * progress. Applications should check {@link #isZoomSupported} before |
| 3767 | * using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3768 | * |
| 3769 | * @return the current zoom value. The range is 0 to {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3770 | * #getMaxZoom}. 0 means the camera is not zoomed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3771 | */ |
| 3772 | public int getZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3773 | return getInt(KEY_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3777 | * Sets current zoom value. If the camera is zoomed (value > 0), the |
| 3778 | * actual picture size may be smaller than picture size setting. |
| 3779 | * Applications can check the actual picture size after picture is |
| 3780 | * returned from {@link PictureCallback}. The preview size remains the |
| 3781 | * same in zoom. Applications should check {@link #isZoomSupported} |
| 3782 | * before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3783 | * |
| 3784 | * @param value zoom value. The valid range is 0 to {@link #getMaxZoom}. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3785 | */ |
| 3786 | public void setZoom(int value) { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3787 | set(KEY_ZOOM, value); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | /** |
| 3791 | * Returns true if zoom is supported. Applications should call this |
| 3792 | * before using other zoom methods. |
| 3793 | * |
| 3794 | * @return true if zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3795 | */ |
| 3796 | public boolean isZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3797 | String str = get(KEY_ZOOM_SUPPORTED); |
| 3798 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * Gets the maximum zoom value allowed for snapshot. This is the maximum |
| 3803 | * value that applications can set to {@link #setZoom(int)}. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3804 | * Applications should call {@link #isZoomSupported} before using this |
| 3805 | * method. This value may change in different preview size. Applications |
| 3806 | * should call this again after setting preview size. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3807 | * |
| 3808 | * @return the maximum zoom value supported by the camera. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3809 | */ |
| 3810 | public int getMaxZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3811 | return getInt(KEY_MAX_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3815 | * Gets the zoom ratios of all zoom values. Applications should check |
| 3816 | * {@link #isZoomSupported} before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3817 | * |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3818 | * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is |
| 3819 | * returned as 320. The number of elements is {@link |
| 3820 | * #getMaxZoom} + 1. The list is sorted from small to large. The |
| 3821 | * first element is always 100. The last element is the zoom |
| 3822 | * ratio of the maximum zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3823 | */ |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3824 | public List<Integer> getZoomRatios() { |
| 3825 | return splitInt(get(KEY_ZOOM_RATIOS)); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * Returns true if smooth zoom is supported. Applications should call |
| 3830 | * this before using other smooth zoom methods. |
| 3831 | * |
| 3832 | * @return true if smooth zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3833 | */ |
| 3834 | public boolean isSmoothZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 3835 | String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); |
| 3836 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3837 | } |
| 3838 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3839 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3840 | * <p>Gets the distances from the camera to where an object appears to be |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3841 | * in focus. The object is sharpest at the optimal focus distance. The |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3842 | * depth of field is the far focus distance minus near focus distance.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3843 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3844 | * <p>Focus distances may change after calling {@link |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3845 | * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link |
| 3846 | * #startPreview()}. Applications can call {@link #getParameters()} |
| 3847 | * and this method anytime to get the latest focus distances. If the |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3848 | * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3849 | * from time to time.</p> |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3850 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3851 | * <p>This method is intended to estimate the distance between the camera |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3852 | * and the subject. After autofocus, the subject distance may be within |
| 3853 | * near and far focus distance. However, the precision depends on the |
| 3854 | * camera hardware, autofocus algorithm, the focus area, and the scene. |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3855 | * The error can be large and it should be only used as a reference.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3856 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3857 | * <p>Far focus distance >= optimal focus distance >= near focus distance. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3858 | * If the focus distance is infinity, the value will be |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3859 | * {@code Float.POSITIVE_INFINITY}.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3860 | * |
| 3861 | * @param output focus distances in meters. output must be a float |
| 3862 | * array with three elements. Near focus distance, optimal focus |
| 3863 | * distance, and far focus distance will be filled in the array. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 3864 | * @see #FOCUS_DISTANCE_NEAR_INDEX |
| 3865 | * @see #FOCUS_DISTANCE_OPTIMAL_INDEX |
| 3866 | * @see #FOCUS_DISTANCE_FAR_INDEX |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3867 | */ |
| 3868 | public void getFocusDistances(float[] output) { |
| 3869 | if (output == null || output.length != 3) { |
| 3870 | throw new IllegalArgumentException( |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 3871 | "output must be a float array with three elements."); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3872 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3873 | splitFloat(get(KEY_FOCUS_DISTANCES), output); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 3874 | } |
| 3875 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3876 | /** |
| 3877 | * Gets the maximum number of focus areas supported. This is the maximum |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3878 | * length of the list in {@link #setFocusAreas(List)} and |
| 3879 | * {@link #getFocusAreas()}. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3880 | * |
| 3881 | * @return the maximum number of focus areas supported by the camera. |
| 3882 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3883 | */ |
| 3884 | public int getMaxNumFocusAreas() { |
| 3885 | return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); |
| 3886 | } |
| 3887 | |
| 3888 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3889 | * <p>Gets the current focus areas. Camera driver uses the areas to decide |
| 3890 | * focus.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3891 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3892 | * <p>Before using this API or {@link #setFocusAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3893 | * call {@link #getMaxNumFocusAreas()} to know the maximum number of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3894 | * focus areas first. If the value is 0, focus area is not supported.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3895 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3896 | * <p>Each focus area is a rectangle with specified weight. The direction |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3897 | * is relative to the sensor orientation, that is, what the sensor sees. |
| 3898 | * The direction is not affected by the rotation or mirroring of |
| 3899 | * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle |
| 3900 | * range from -1000 to 1000. (-1000, -1000) is the upper left point. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 3901 | * (1000, 1000) is the lower right point. The width and height of focus |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3902 | * areas cannot be 0 or negative.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3903 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3904 | * <p>The weight must range from 1 to 1000. The weight should be |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 3905 | * interpreted as a per-pixel weight - all pixels in the area have the |
| 3906 | * specified weight. This means a small area with the same weight as a |
| 3907 | * larger area will have less influence on the focusing than the larger |
| 3908 | * area. Focus areas can partially overlap and the driver will add the |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3909 | * weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3910 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3911 | * <p>A special case of a {@code null} focus area list means the driver is |
| 3912 | * free to select focus targets as it wants. For example, the driver may |
| 3913 | * use more signals to select focus areas and change them |
| 3914 | * dynamically. Apps can set the focus area list to {@code null} if they |
| 3915 | * want the driver to completely control focusing.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3916 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3917 | * <p>Focus areas are relative to the current field of view |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3918 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 3919 | * represents the top of the currently visible camera frame. The focus |
| 3920 | * area cannot be set to be outside the current field of view, even |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3921 | * when using zoom.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3922 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3923 | * <p>Focus area only has effect if the current focus mode is |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 3924 | * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, |
| 3925 | * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or |
| 3926 | * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3927 | * |
| 3928 | * @return a list of current focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3929 | */ |
| 3930 | public List<Area> getFocusAreas() { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3931 | return splitArea(get(KEY_FOCUS_AREAS)); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | /** |
| 3935 | * Sets focus areas. See {@link #getFocusAreas()} for documentation. |
| 3936 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3937 | * @param focusAreas the focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3938 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 3939 | */ |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3940 | public void setFocusAreas(List<Area> focusAreas) { |
| 3941 | set(KEY_FOCUS_AREAS, focusAreas); |
| 3942 | } |
| 3943 | |
| 3944 | /** |
| 3945 | * Gets the maximum number of metering areas supported. This is the |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3946 | * maximum length of the list in {@link #setMeteringAreas(List)} and |
| 3947 | * {@link #getMeteringAreas()}. |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3948 | * |
| 3949 | * @return the maximum number of metering areas supported by the camera. |
| 3950 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3951 | */ |
| 3952 | public int getMaxNumMeteringAreas() { |
| 3953 | return getInt(KEY_MAX_NUM_METERING_AREAS, 0); |
| 3954 | } |
| 3955 | |
| 3956 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3957 | * <p>Gets the current metering areas. Camera driver uses these areas to |
| 3958 | * decide exposure.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3959 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3960 | * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 3961 | * call {@link #getMaxNumMeteringAreas()} to know the maximum number of |
| 3962 | * metering areas first. If the value is 0, metering area is not |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3963 | * supported.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3964 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3965 | * <p>Each metering area is a rectangle with specified weight. The |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3966 | * direction is relative to the sensor orientation, that is, what the |
| 3967 | * sensor sees. The direction is not affected by the rotation or |
| 3968 | * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the |
| 3969 | * rectangle range from -1000 to 1000. (-1000, -1000) is the upper left |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 3970 | * point. (1000, 1000) is the lower right point. The width and height of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3971 | * metering areas cannot be 0 or negative.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3972 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3973 | * <p>The weight must range from 1 to 1000, and represents a weight for |
Eino-Ville Talvala | 4e396e0 | 2011-04-21 09:23:15 -0700 | [diff] [blame] | 3974 | * every pixel in the area. This means that a large metering area with |
| 3975 | * the same weight as a smaller area will have more effect in the |
| 3976 | * metering result. Metering areas can partially overlap and the driver |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3977 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3978 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3979 | * <p>A special case of a {@code null} metering area list means the driver |
| 3980 | * is free to meter as it chooses. For example, the driver may use more |
| 3981 | * signals to select metering areas and change them dynamically. Apps |
| 3982 | * can set the metering area list to {@code null} if they want the |
| 3983 | * driver to completely control metering.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3984 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3985 | * <p>Metering areas are relative to the current field of view |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3986 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 3987 | * represents the top of the currently visible camera frame. The |
| 3988 | * metering area cannot be set to be outside the current field of view, |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3989 | * even when using zoom.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3990 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3991 | * <p>No matter what metering areas are, the final exposure are compensated |
| 3992 | * by {@link #setExposureCompensation(int)}.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3993 | * |
| 3994 | * @return a list of current metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3995 | */ |
| 3996 | public List<Area> getMeteringAreas() { |
Wu-cheng Li | d8aab93 | 2011-06-21 11:50:43 +0800 | [diff] [blame] | 3997 | return splitArea(get(KEY_METERING_AREAS)); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3998 | } |
| 3999 | |
| 4000 | /** |
| 4001 | * Sets metering areas. See {@link #getMeteringAreas()} for |
| 4002 | * documentation. |
| 4003 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4004 | * @param meteringAreas the metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4005 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4006 | */ |
| 4007 | public void setMeteringAreas(List<Area> meteringAreas) { |
| 4008 | set(KEY_METERING_AREAS, meteringAreas); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4009 | } |
| 4010 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4011 | /** |
| 4012 | * Gets the maximum number of detected faces supported. This is the |
| 4013 | * maximum length of the list returned from {@link FaceDetectionListener}. |
| 4014 | * If the return value is 0, face detection of the specified type is not |
| 4015 | * supported. |
| 4016 | * |
| 4017 | * @return the maximum number of detected face supported by the camera. |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 4018 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4019 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 4020 | public int getMaxNumDetectedFaces() { |
| 4021 | return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4022 | } |
| 4023 | |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4024 | /** |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4025 | * Sets recording mode hint. This tells the camera that the intent of |
| 4026 | * the application is to record videos {@link |
| 4027 | * android.media.MediaRecorder#start()}, not to take still pictures |
| 4028 | * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 4029 | * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can |
| 4030 | * allow MediaRecorder.start() to start faster or with fewer glitches on |
| 4031 | * output. This should be called before starting preview for the best |
| 4032 | * result, but can be changed while the preview is active. The default |
| 4033 | * value is false. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4034 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4035 | * The app can still call takePicture() when the hint is true or call |
| 4036 | * MediaRecorder.start() when the hint is false. But the performance may |
| 4037 | * be worse. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4038 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4039 | * @param hint true if the apps intend to record videos using |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4040 | * {@link android.media.MediaRecorder}. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4041 | */ |
| 4042 | public void setRecordingHint(boolean hint) { |
| 4043 | set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); |
| 4044 | } |
| 4045 | |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4046 | /** |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4047 | * <p>Returns true if video snapshot is supported. That is, applications |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4048 | * can call {@link #takePicture(Camera.ShutterCallback, |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4049 | * Camera.PictureCallback, Camera.PictureCallback, |
| 4050 | * Camera.PictureCallback)} during recording. Applications do not need |
| 4051 | * to call {@link #startPreview()} after taking a picture. The preview |
| 4052 | * will be still active. Other than that, taking a picture during |
| 4053 | * recording is identical to taking a picture normally. All settings and |
| 4054 | * methods related to takePicture work identically. Ex: |
| 4055 | * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()}, |
| 4056 | * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The |
| 4057 | * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and |
| 4058 | * {@link #FLASH_MODE_ON} also still work, but the video will record the |
| 4059 | * flash.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4060 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4061 | * <p>Applications can set shutter callback as null to avoid the shutter |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4062 | * sound. It is also recommended to set raw picture and post view |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4063 | * callbacks to null to avoid the interrupt of preview display.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4064 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4065 | * <p>Field-of-view of the recorded video may be different from that of the |
| 4066 | * captured pictures. The maximum size of a video snapshot may be |
| 4067 | * smaller than that for regular still captures. If the current picture |
| 4068 | * size is set higher than can be supported by video snapshot, the |
| 4069 | * picture will be captured at the maximum supported size instead.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4070 | * |
| 4071 | * @return true if video snapshot is supported. |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4072 | */ |
| 4073 | public boolean isVideoSnapshotSupported() { |
| 4074 | String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); |
| 4075 | return TRUE.equals(str); |
| 4076 | } |
| 4077 | |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4078 | /** |
| 4079 | * <p>Enables and disables video stabilization. Use |
| 4080 | * {@link #isVideoStabilizationSupported} to determine if calling this |
| 4081 | * method is valid.</p> |
| 4082 | * |
| 4083 | * <p>Video stabilization reduces the shaking due to the motion of the |
| 4084 | * camera in both the preview stream and in recorded videos, including |
| 4085 | * data received from the preview callback. It does not reduce motion |
| 4086 | * blur in images captured with |
| 4087 | * {@link Camera#takePicture takePicture}.</p> |
| 4088 | * |
| 4089 | * <p>Video stabilization can be enabled and disabled while preview or |
| 4090 | * recording is active, but toggling it may cause a jump in the video |
| 4091 | * stream that may be undesirable in a recorded video.</p> |
| 4092 | * |
| 4093 | * @param toggle Set to true to enable video stabilization, and false to |
| 4094 | * disable video stabilization. |
| 4095 | * @see #isVideoStabilizationSupported() |
| 4096 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4097 | */ |
| 4098 | public void setVideoStabilization(boolean toggle) { |
| 4099 | set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); |
| 4100 | } |
| 4101 | |
| 4102 | /** |
| 4103 | * Get the current state of video stabilization. See |
| 4104 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4105 | * |
| 4106 | * @return true if video stabilization is enabled |
| 4107 | * @see #isVideoStabilizationSupported() |
| 4108 | * @see #setVideoStabilization(boolean) |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4109 | */ |
| 4110 | public boolean getVideoStabilization() { |
| 4111 | String str = get(KEY_VIDEO_STABILIZATION); |
| 4112 | return TRUE.equals(str); |
| 4113 | } |
| 4114 | |
| 4115 | /** |
| 4116 | * Returns true if video stabilization is supported. See |
| 4117 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4118 | * |
| 4119 | * @return true if video stabilization is supported |
| 4120 | * @see #setVideoStabilization(boolean) |
| 4121 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4122 | */ |
| 4123 | public boolean isVideoStabilizationSupported() { |
| 4124 | String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); |
| 4125 | return TRUE.equals(str); |
| 4126 | } |
| 4127 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4128 | // Splits a comma delimited string to an ArrayList of String. |
| 4129 | // Return null if the passing string is null or the size is 0. |
| 4130 | private ArrayList<String> split(String str) { |
| 4131 | if (str == null) return null; |
| 4132 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4133 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4134 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4135 | ArrayList<String> substrings = new ArrayList<String>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4136 | for (String s : splitter) { |
| 4137 | substrings.add(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4138 | } |
| 4139 | return substrings; |
| 4140 | } |
| 4141 | |
| 4142 | // Splits a comma delimited string to an ArrayList of Integer. |
| 4143 | // Return null if the passing string is null or the size is 0. |
| 4144 | private ArrayList<Integer> splitInt(String str) { |
| 4145 | if (str == null) return null; |
| 4146 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4147 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4148 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4149 | ArrayList<Integer> substrings = new ArrayList<Integer>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4150 | for (String s : splitter) { |
| 4151 | substrings.add(Integer.parseInt(s)); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4152 | } |
| 4153 | if (substrings.size() == 0) return null; |
| 4154 | return substrings; |
| 4155 | } |
| 4156 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4157 | private void splitInt(String str, int[] output) { |
| 4158 | if (str == null) return; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4159 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4160 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4161 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4162 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4163 | for (String s : splitter) { |
| 4164 | output[index++] = Integer.parseInt(s); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4165 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | // Splits a comma delimited string to an ArrayList of Float. |
| 4169 | private void splitFloat(String str, float[] output) { |
| 4170 | if (str == null) return; |
| 4171 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4172 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4173 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4174 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4175 | for (String s : splitter) { |
| 4176 | output[index++] = Float.parseFloat(s); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4177 | } |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4178 | } |
| 4179 | |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4180 | // Returns the value of a float parameter. |
| 4181 | private float getFloat(String key, float defaultValue) { |
| 4182 | try { |
| 4183 | return Float.parseFloat(mMap.get(key)); |
| 4184 | } catch (NumberFormatException ex) { |
| 4185 | return defaultValue; |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | // Returns the value of a integer parameter. |
| 4190 | private int getInt(String key, int defaultValue) { |
| 4191 | try { |
| 4192 | return Integer.parseInt(mMap.get(key)); |
| 4193 | } catch (NumberFormatException ex) { |
| 4194 | return defaultValue; |
| 4195 | } |
| 4196 | } |
| 4197 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4198 | // Splits a comma delimited string to an ArrayList of Size. |
| 4199 | // Return null if the passing string is null or the size is 0. |
| 4200 | private ArrayList<Size> splitSize(String str) { |
| 4201 | if (str == null) return null; |
| 4202 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4203 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4204 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4205 | ArrayList<Size> sizeList = new ArrayList<Size>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4206 | for (String s : splitter) { |
| 4207 | Size size = strToSize(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4208 | if (size != null) sizeList.add(size); |
| 4209 | } |
| 4210 | if (sizeList.size() == 0) return null; |
| 4211 | return sizeList; |
| 4212 | } |
| 4213 | |
| 4214 | // Parses a string (ex: "480x320") to Size object. |
| 4215 | // Return null if the passing string is null. |
| 4216 | private Size strToSize(String str) { |
| 4217 | if (str == null) return null; |
| 4218 | |
| 4219 | int pos = str.indexOf('x'); |
| 4220 | if (pos != -1) { |
| 4221 | String width = str.substring(0, pos); |
| 4222 | String height = str.substring(pos + 1); |
| 4223 | return new Size(Integer.parseInt(width), |
| 4224 | Integer.parseInt(height)); |
| 4225 | } |
| 4226 | Log.e(TAG, "Invalid size parameter string=" + str); |
| 4227 | return null; |
| 4228 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4229 | |
| 4230 | // Splits a comma delimited string to an ArrayList of int array. |
| 4231 | // Example string: "(10000,26623),(10000,30000)". Return null if the |
| 4232 | // passing string is null or the size is 0. |
| 4233 | private ArrayList<int[]> splitRange(String str) { |
| 4234 | if (str == null || str.charAt(0) != '(' |
| 4235 | || str.charAt(str.length() - 1) != ')') { |
| 4236 | Log.e(TAG, "Invalid range list string=" + str); |
| 4237 | return null; |
| 4238 | } |
| 4239 | |
| 4240 | ArrayList<int[]> rangeList = new ArrayList<int[]>(); |
| 4241 | int endIndex, fromIndex = 1; |
| 4242 | do { |
| 4243 | int[] range = new int[2]; |
| 4244 | endIndex = str.indexOf("),(", fromIndex); |
| 4245 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4246 | splitInt(str.substring(fromIndex, endIndex), range); |
| 4247 | rangeList.add(range); |
| 4248 | fromIndex = endIndex + 3; |
| 4249 | } while (endIndex != str.length() - 1); |
| 4250 | |
| 4251 | if (rangeList.size() == 0) return null; |
| 4252 | return rangeList; |
| 4253 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4254 | |
| 4255 | // Splits a comma delimited string to an ArrayList of Area objects. |
| 4256 | // Example string: "(-10,-10,0,0,300),(0,0,10,10,700)". Return null if |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4257 | // the passing string is null or the size is 0 or (0,0,0,0,0). |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4258 | private ArrayList<Area> splitArea(String str) { |
| 4259 | if (str == null || str.charAt(0) != '(' |
| 4260 | || str.charAt(str.length() - 1) != ')') { |
| 4261 | Log.e(TAG, "Invalid area string=" + str); |
| 4262 | return null; |
| 4263 | } |
| 4264 | |
| 4265 | ArrayList<Area> result = new ArrayList<Area>(); |
| 4266 | int endIndex, fromIndex = 1; |
| 4267 | int[] array = new int[5]; |
| 4268 | do { |
| 4269 | endIndex = str.indexOf("),(", fromIndex); |
| 4270 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4271 | splitInt(str.substring(fromIndex, endIndex), array); |
| 4272 | Rect rect = new Rect(array[0], array[1], array[2], array[3]); |
| 4273 | result.add(new Area(rect, array[4])); |
| 4274 | fromIndex = endIndex + 3; |
| 4275 | } while (endIndex != str.length() - 1); |
| 4276 | |
| 4277 | if (result.size() == 0) return null; |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4278 | |
| 4279 | if (result.size() == 1) { |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 4280 | Area area = result.get(0); |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4281 | Rect rect = area.rect; |
| 4282 | if (rect.left == 0 && rect.top == 0 && rect.right == 0 |
| 4283 | && rect.bottom == 0 && area.weight == 0) { |
| 4284 | return null; |
| 4285 | } |
| 4286 | } |
| 4287 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4288 | return result; |
| 4289 | } |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 4290 | |
| 4291 | private boolean same(String s1, String s2) { |
| 4292 | if (s1 == null && s2 == null) return true; |
| 4293 | if (s1 != null && s1.equals(s2)) return true; |
| 4294 | return false; |
| 4295 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4296 | }; |
| 4297 | } |