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