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