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