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