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