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; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 168 | /* ### QC ADD-ONS: START */ |
| 169 | private static final int CAMERA_MSG_STATS_DATA = 0x1000; |
| 170 | private static final int CAMERA_MSG_META_DATA = 0x2000; |
| 171 | /* ### QC ADD-ONS: END */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 173 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Ashok Bhat | 4838e33 | 2014-01-03 14:37:19 +0000 | [diff] [blame] | 174 | private long mNativeContext; // accessed by native methods |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | private EventHandler mEventHandler; |
| 176 | private ShutterCallback mShutterCallback; |
| 177 | private PictureCallback mRawImageCallback; |
| 178 | private PictureCallback mJpegCallback; |
| 179 | private PreviewCallback mPreviewCallback; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 180 | private boolean mUsingPreviewAllocation; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 181 | private PictureCallback mPostviewCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | private AutoFocusCallback mAutoFocusCallback; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 183 | private AutoFocusMoveCallback mAutoFocusMoveCallback; |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 184 | private OnZoomChangeListener mZoomListener; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 185 | private FaceDetectionListener mFaceListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | private ErrorCallback mErrorCallback; |
Yin-Chia Yeh | a07cd32 | 2018-05-31 12:11:42 -0700 | [diff] [blame] | 187 | private ErrorCallback mDetailedErrorCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | private boolean mOneShot; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 189 | private boolean mWithBuffer; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 190 | private boolean mFaceDetectionRunning = false; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 191 | private final Object mAutoFocusCallbackLock = new Object(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 192 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 193 | private final Object mShutterSoundLock = new Object(); |
| 194 | // for AppOps |
| 195 | private @Nullable IAppOpsService mAppOps; |
| 196 | private IAppOpsCallback mAppOpsCallback; |
| 197 | @GuardedBy("mShutterSoundLock") |
| 198 | private boolean mHasAppOpsPlayAudio = true; |
| 199 | @GuardedBy("mShutterSoundLock") |
| 200 | private boolean mShutterSoundEnabledFromApp = true; |
| 201 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 202 | private static final int NO_ERROR = 0; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 203 | private static final int EACCESS = -13; |
| 204 | private static final int ENODEV = -19; |
| 205 | private static final int EBUSY = -16; |
| 206 | private static final int EINVAL = -22; |
| 207 | private static final int ENOSYS = -38; |
| 208 | private static final int EUSERS = -87; |
| 209 | private static final int EOPNOTSUPP = -95; |
| 210 | /* ### QC ADD-ONS: START */ |
| 211 | private CameraDataCallback mCameraDataCallback; |
| 212 | private CameraMetaDataCallback mCameraMetaDataCallback; |
| 213 | /* ### QC ADD-ONS: END */ |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | /** |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 216 | * Broadcast Action: A new picture is taken by the camera, and the entry of |
| 217 | * the picture has been added to the media store. |
| 218 | * {@link android.content.Intent#getData} is URI of the picture. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 219 | * |
| 220 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 221 | * applications are recommended to use |
| 222 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 223 | * instead.</p> |
| 224 | * |
| 225 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 226 | * 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] | 227 | * 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] | 228 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 229 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 230 | */ |
| 231 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 232 | public static final String ACTION_NEW_PICTURE = "android.hardware.action.NEW_PICTURE"; |
| 233 | |
| 234 | /** |
| 235 | * Broadcast Action: A new video is recorded by the camera, and the entry |
| 236 | * of the video has been added to the media store. |
| 237 | * {@link android.content.Intent#getData} is URI of the video. |
Dianne Hackborn | 5da9e94 | 2017-03-10 13:30:06 -0800 | [diff] [blame] | 238 | * |
| 239 | * <p>In {@link android.os.Build.VERSION_CODES#N Android N} this broadcast was removed, and |
| 240 | * applications are recommended to use |
| 241 | * {@link android.app.job.JobInfo.Builder JobInfo.Builder}.{@link android.app.job.JobInfo.Builder#addTriggerContentUri} |
| 242 | * instead.</p> |
| 243 | * |
| 244 | * <p>In {@link android.os.Build.VERSION_CODES#O Android O} this broadcast has been brought |
| 245 | * 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] | 246 | * 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] | 247 | * being taken, however anything doing heavy work (or needing to be launched) as a result of |
| 248 | * this should still use JobScheduler.</p> |
Wu-cheng Li | 10e09c6 | 2011-07-18 09:09:41 +0800 | [diff] [blame] | 249 | */ |
| 250 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 251 | public static final String ACTION_NEW_VIDEO = "android.hardware.action.NEW_VIDEO"; |
| 252 | |
| 253 | /** |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 254 | * Camera HAL device API version 1.0 |
| 255 | * @hide |
| 256 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 257 | @UnsupportedAppUsage |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 258 | public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100; |
| 259 | |
| 260 | /** |
| 261 | * A constant meaning the normal camera connect/open will be used. |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 262 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 263 | private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2; |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 264 | |
| 265 | /** |
| 266 | * Used to indicate HAL version un-specified. |
| 267 | */ |
| 268 | private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1; |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 269 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 270 | /** |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 271 | * Hardware face detection. It does not use much CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 272 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 273 | private static final int CAMERA_FACE_DETECTION_HW = 0; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 274 | |
| 275 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 276 | * Software face detection. It uses some CPU. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 277 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 278 | private static final int CAMERA_FACE_DETECTION_SW = 1; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 279 | |
| 280 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 281 | * Returns the number of physical cameras available on this device. |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 282 | * The return value of this method might change dynamically if the device |
| 283 | * supports external cameras and an external camera is connected or |
| 284 | * disconnected. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 285 | * |
Shuzhen Wang | e7d3cd0 | 2018-05-31 11:41:39 -0700 | [diff] [blame] | 286 | * If there is a |
| 287 | * {@link android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA |
| 288 | * 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] | 289 | * 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] | 290 | * Use camera2 API to see all cameras. |
| 291 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 292 | * @return total number of accessible camera devices, or 0 if there are no |
| 293 | * cameras or an error was encountered enumerating them. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | */ |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 295 | public native static int getNumberOfCameras(); |
| 296 | |
| 297 | /** |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 298 | * Returns the information about a particular camera. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 299 | * 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] | 300 | * |
| 301 | * @throws RuntimeException if an invalid ID is provided, or if there is an |
| 302 | * error retrieving the information (generally due to a hardware or other |
| 303 | * low-level failure). |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 304 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 305 | public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) { |
| 306 | _getCameraInfo(cameraId, cameraInfo); |
| 307 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 308 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 309 | try { |
| 310 | if (audioService.isCameraSoundForced()) { |
| 311 | // Only set this when sound is forced; otherwise let native code |
| 312 | // decide. |
| 313 | cameraInfo.canDisableShutterSound = false; |
| 314 | } |
| 315 | } catch (RemoteException e) { |
| 316 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 317 | } |
| 318 | } |
| 319 | private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo); |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 320 | |
| 321 | /** |
| 322 | * Information about a camera |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 323 | * |
| 324 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 325 | * applications. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 326 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 327 | @Deprecated |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 328 | public static class CameraInfo { |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 329 | /** |
| 330 | * The facing of the camera is opposite to that of the screen. |
| 331 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 332 | public static final int CAMERA_FACING_BACK = 0; |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * The facing of the camera is the same as that of the screen. |
| 336 | */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 337 | public static final int CAMERA_FACING_FRONT = 1; |
| 338 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 339 | /* ### QC ADD-ONS: START TBD*/ |
| 340 | /** @hide |
| 341 | * camera is in ZSL mode. |
| 342 | */ |
| 343 | public static final int CAMERA_SUPPORT_MODE_ZSL = 2; |
| 344 | |
| 345 | /** @hide |
| 346 | * camera is in non-ZSL mode. |
| 347 | */ |
| 348 | public static final int CAMERA_SUPPORT_MODE_NONZSL = 3; |
| 349 | /* ### QC ADD-ONS: END */ |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 350 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 351 | * The direction that the camera faces. It should be |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 352 | * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. |
| 353 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 354 | public int facing; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 355 | |
| 356 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 357 | * <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] | 358 | * 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] | 359 | * 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] | 360 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 361 | * <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] | 362 | * back-facing camera sensor is mounted in landscape. You are looking at |
| 363 | * the screen. If the top side of the camera sensor is aligned with the |
| 364 | * right edge of the screen in natural orientation, the value should be |
| 365 | * 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] | 366 | * the right of the screen, the value should be 270.</p> |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 367 | * |
| 368 | * @see #setDisplayOrientation(int) |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 369 | * @see Parameters#setRotation(int) |
| 370 | * @see Parameters#setPreviewSize(int, int) |
| 371 | * @see Parameters#setPictureSize(int, int) |
| 372 | * @see Parameters#setJpegThumbnailSize(int, int) |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 373 | */ |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 374 | public int orientation; |
Eino-Ville Talvala | f7c6c5a | 2012-09-19 11:46:11 -0700 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * <p>Whether the shutter sound can be disabled.</p> |
| 378 | * |
| 379 | * <p>On some devices, the camera shutter sound cannot be turned off |
| 380 | * through {@link #enableShutterSound enableShutterSound}. This field |
| 381 | * can be used to determine whether a call to disable the shutter sound |
| 382 | * will succeed.</p> |
| 383 | * |
| 384 | * <p>If this field is set to true, then a call of |
| 385 | * {@code enableShutterSound(false)} will be successful. If set to |
| 386 | * false, then that call will fail, and the shutter sound will be played |
| 387 | * when {@link Camera#takePicture takePicture} is called.</p> |
| 388 | */ |
| 389 | public boolean canDisableShutterSound; |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | /** |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 393 | * Creates a new Camera object to access a particular hardware camera. If |
| 394 | * the same camera is opened by other applications, this will throw a |
| 395 | * RuntimeException. |
| 396 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 397 | * <p>You must call {@link #release()} when you are done using the camera, |
| 398 | * otherwise it will remain locked and be unavailable to other applications. |
| 399 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 400 | * <p>Your application should only have one Camera object active at a time |
| 401 | * for a particular hardware camera. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 402 | * |
| 403 | * <p>Callbacks from other methods are delivered to the event loop of the |
| 404 | * thread which called open(). If this thread has no event loop, then |
| 405 | * callbacks are delivered to the main application event loop. If there |
| 406 | * is no main application event loop, callbacks are not delivered. |
| 407 | * |
| 408 | * <p class="caution"><b>Caution:</b> On some devices, this method may |
| 409 | * take a long time to complete. It is best to call this method from a |
| 410 | * worker thread (possibly using {@link android.os.AsyncTask}) to avoid |
| 411 | * blocking the main application UI thread. |
| 412 | * |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 413 | * @param cameraId the hardware camera to access, between 0 and |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 414 | * {@link #getNumberOfCameras()}-1. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 415 | * @return a new Camera object, connected, locked and ready for use. |
Wu-cheng Li | a1c41e1 | 2012-02-23 19:01:00 -0800 | [diff] [blame] | 416 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 417 | * camera is in use by another process or device policy manager has |
| 418 | * disabled the camera). |
Wu-cheng Li | facc8ce | 2011-06-17 13:09:40 +0800 | [diff] [blame] | 419 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 420 | */ |
| 421 | public static Camera open(int cameraId) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 422 | return new Camera(cameraId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 425 | /** |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 426 | * Creates a new Camera object to access the first back-facing camera on the |
| 427 | * 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] | 428 | * null. Otherwise acts like the {@link #open(int)} call. |
| 429 | * |
| 430 | * @return a new Camera object for the first back-facing camera, or null if there is no |
| 431 | * backfacing camera |
Wu-cheng Li | 7836660 | 2010-09-15 14:08:15 -0700 | [diff] [blame] | 432 | * @see #open(int) |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 433 | */ |
| 434 | public static Camera open() { |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 435 | int numberOfCameras = getNumberOfCameras(); |
| 436 | CameraInfo cameraInfo = new CameraInfo(); |
| 437 | for (int i = 0; i < numberOfCameras; i++) { |
| 438 | getCameraInfo(i, cameraInfo); |
| 439 | if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 440 | return new Camera(i); |
Wu-cheng Li | a48b70f | 2010-11-09 01:55:44 +0800 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | return null; |
Chih-Chung Chang | e25cc65 | 2010-05-06 16:36:58 +0800 | [diff] [blame] | 444 | } |
| 445 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 446 | /** |
| 447 | * Creates a new Camera object to access a particular hardware camera with |
| 448 | * given hal API version. If the same camera is opened by other applications |
| 449 | * or the hal API version is not supported by this device, this will throw a |
| 450 | * RuntimeException. |
| 451 | * <p> |
| 452 | * You must call {@link #release()} when you are done using the camera, |
| 453 | * otherwise it will remain locked and be unavailable to other applications. |
| 454 | * <p> |
| 455 | * Your application should only have one Camera object active at a time for |
| 456 | * a particular hardware camera. |
| 457 | * <p> |
| 458 | * Callbacks from other methods are delivered to the event loop of the |
| 459 | * thread which called open(). If this thread has no event loop, then |
| 460 | * callbacks are delivered to the main application event loop. If there is |
| 461 | * no main application event loop, callbacks are not delivered. |
| 462 | * <p class="caution"> |
| 463 | * <b>Caution:</b> On some devices, this method may take a long time to |
| 464 | * complete. It is best to call this method from a worker thread (possibly |
| 465 | * using {@link android.os.AsyncTask}) to avoid blocking the main |
| 466 | * application UI thread. |
| 467 | * |
| 468 | * @param cameraId The hardware camera to access, between 0 and |
| 469 | * {@link #getNumberOfCameras()}-1. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 470 | * @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] | 471 | * @return a new Camera object, connected, locked and ready for use. |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 472 | * |
| 473 | * @throws IllegalArgumentException if the {@code halVersion} is invalid |
| 474 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 475 | * @throws RuntimeException if opening the camera fails (for example, if the |
| 476 | * camera is in use by another process or device policy manager has disabled |
| 477 | * the camera). |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 478 | * |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 479 | * @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName) |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 480 | * @see #CAMERA_HAL_API_VERSION_1_0 |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 481 | * |
| 482 | * @hide |
| 483 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 484 | @UnsupportedAppUsage |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 485 | public static Camera openLegacy(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 486 | if (halVersion < CAMERA_HAL_API_VERSION_1_0) { |
| 487 | throw new IllegalArgumentException("Invalid HAL version " + halVersion); |
| 488 | } |
| 489 | |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 490 | return new Camera(cameraId, halVersion); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Create a legacy camera object. |
| 495 | * |
| 496 | * @param cameraId The hardware camera to access, between 0 and |
| 497 | * {@link #getNumberOfCameras()}-1. |
| 498 | * @param halVersion The HAL API version this camera device to be opened as. |
| 499 | */ |
| 500 | private Camera(int cameraId, int halVersion) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 501 | int err = cameraInitVersion(cameraId, halVersion); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 502 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 503 | if (err == -EACCES) { |
| 504 | throw new RuntimeException("Fail to connect to camera service"); |
| 505 | } else if (err == -ENODEV) { |
| 506 | throw new RuntimeException("Camera initialization failed"); |
| 507 | } else if (err == -ENOSYS) { |
| 508 | throw new RuntimeException("Camera initialization failed because some methods" |
| 509 | + " are not implemented"); |
| 510 | } else if (err == -EOPNOTSUPP) { |
| 511 | throw new RuntimeException("Camera initialization failed because the hal" |
| 512 | + " version is not supported by this device"); |
| 513 | } else if (err == -EINVAL) { |
| 514 | throw new RuntimeException("Camera initialization failed because the input" |
| 515 | + " arugments are invalid"); |
| 516 | } else if (err == -EBUSY) { |
| 517 | throw new RuntimeException("Camera initialization failed because the camera" |
| 518 | + " device was already opened"); |
| 519 | } else if (err == -EUSERS) { |
| 520 | throw new RuntimeException("Camera initialization failed because the max" |
| 521 | + " number of camera devices were already opened"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 522 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 523 | // Should never hit this. |
| 524 | throw new RuntimeException("Unknown camera error"); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 528 | private int cameraInitVersion(int cameraId, int halVersion) { |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 529 | mShutterCallback = null; |
| 530 | mRawImageCallback = null; |
| 531 | mJpegCallback = null; |
| 532 | mPreviewCallback = null; |
| 533 | mPostviewCallback = null; |
| 534 | mUsingPreviewAllocation = false; |
| 535 | mZoomListener = null; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 536 | /* ### QC ADD-ONS: START */ |
| 537 | mCameraDataCallback = null; |
| 538 | mCameraMetaDataCallback = null; |
| 539 | /* ### QC ADD-ONS: END */ |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 540 | |
| 541 | Looper looper; |
| 542 | if ((looper = Looper.myLooper()) != null) { |
| 543 | mEventHandler = new EventHandler(this, looper); |
| 544 | } else if ((looper = Looper.getMainLooper()) != null) { |
| 545 | mEventHandler = new EventHandler(this, looper); |
| 546 | } else { |
| 547 | mEventHandler = null; |
| 548 | } |
| 549 | |
Svetoslav | fbf0eca | 2015-05-01 16:52:41 -0700 | [diff] [blame] | 550 | return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, |
| 551 | ActivityThread.currentOpPackageName()); |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 554 | private int cameraInitNormal(int cameraId) { |
| 555 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT); |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Connect to the camera service using #connectLegacy |
| 560 | * |
| 561 | * <p> |
| 562 | * This acts the same as normal except that it will return |
| 563 | * the detailed error code if open fails instead of |
| 564 | * converting everything into {@code NO_INIT}.</p> |
| 565 | * |
| 566 | * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p> |
| 567 | * |
| 568 | * @return a detailed errno error code, or {@code NO_ERROR} on success |
| 569 | * |
| 570 | * @hide |
| 571 | */ |
| 572 | public int cameraInitUnspecified(int cameraId) { |
| 573 | return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED); |
| 574 | } |
| 575 | |
| 576 | /** used by Camera#open, Camera#open(int) */ |
Wu-cheng Li | 7bc1b21 | 2012-04-19 12:23:31 +0800 | [diff] [blame] | 577 | Camera(int cameraId) { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 578 | int err = cameraInitNormal(cameraId); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 579 | if (checkInitErrors(err)) { |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 580 | if (err == -EACCES) { |
| 581 | throw new RuntimeException("Fail to connect to camera service"); |
| 582 | } else if (err == -ENODEV) { |
| 583 | throw new RuntimeException("Camera initialization failed"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 584 | } |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 585 | // Should never hit this. |
| 586 | throw new RuntimeException("Unknown camera error"); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 587 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 588 | initAppOps(); |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 591 | |
| 592 | /** |
| 593 | * @hide |
| 594 | */ |
| 595 | public static boolean checkInitErrors(int err) { |
| 596 | return err != NO_ERROR; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * @hide |
| 601 | */ |
| 602 | public static Camera openUninitialized() { |
| 603 | return new Camera(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 605 | |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 606 | /** |
| 607 | * An empty Camera for testing purpose. |
| 608 | */ |
Daichi Hirono | 2dba5c8 | 2018-06-25 11:16:41 +0900 | [diff] [blame] | 609 | Camera() {} |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 610 | |
| 611 | private void initAppOps() { |
| 612 | IBinder b = ServiceManager.getService(Context.APP_OPS_SERVICE); |
| 613 | mAppOps = IAppOpsService.Stub.asInterface(b); |
| 614 | // initialize mHasAppOpsPlayAudio |
| 615 | updateAppOpsPlayAudio(); |
| 616 | // register a callback to monitor whether the OP_PLAY_AUDIO is still allowed |
| 617 | mAppOpsCallback = new IAppOpsCallbackWrapper(this); |
| 618 | try { |
| 619 | mAppOps.startWatchingMode(AppOpsManager.OP_PLAY_AUDIO, |
| 620 | ActivityThread.currentPackageName(), mAppOpsCallback); |
| 621 | } catch (RemoteException e) { |
| 622 | Log.e(TAG, "Error registering appOps callback", e); |
| 623 | mHasAppOpsPlayAudio = false; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | private void releaseAppOps() { |
| 628 | try { |
| 629 | if (mAppOps != null) { |
| 630 | mAppOps.stopWatchingMode(mAppOpsCallback); |
| 631 | } |
| 632 | } catch (Exception e) { |
| 633 | // nothing to do here, the object is supposed to be released anyway |
| 634 | } |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 635 | } |
| 636 | |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 637 | @Override |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 638 | protected void finalize() { |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 639 | release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 641 | |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 642 | @UnsupportedAppUsage |
Zhijun He | 4c91380 | 2014-06-16 16:42:35 -0700 | [diff] [blame] | 643 | 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] | 644 | String packageName); |
| 645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | private native final void native_release(); |
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 | |
| 649 | /** |
| 650 | * Disconnects and releases the Camera object resources. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 651 | * |
| 652 | * <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] | 653 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 654 | public final void release() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | native_release(); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 656 | mFaceDetectionRunning = false; |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 657 | releaseAppOps(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 661 | * Unlocks the camera to allow another process to access it. |
| 662 | * Normally, the camera is locked to the process with an active Camera |
| 663 | * object until {@link #release()} is called. To allow rapid handoff |
| 664 | * between processes, you can call this method to release the camera |
| 665 | * temporarily for another process to use; once the other process is done |
| 666 | * you can call {@link #reconnect()} to reclaim the camera. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 668 | * <p>This must be done before calling |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 669 | * {@link android.media.MediaRecorder#setCamera(Camera)}. This cannot be |
| 670 | * called after recording starts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 672 | * <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] | 673 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 674 | * @throws RuntimeException if the camera cannot be unlocked. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | */ |
Wu-cheng Li | ffe1cf2 | 2009-09-10 16:49:17 +0800 | [diff] [blame] | 676 | public native final void unlock(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 679 | * Re-locks the camera to prevent other processes from accessing it. |
| 680 | * Camera objects are locked by default unless {@link #unlock()} is |
| 681 | * called. Normally {@link #reconnect()} is used instead. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 682 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 683 | * <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] | 684 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 685 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 686 | * after recording starts or stops. |
| 687 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 688 | * <p>If you are not recording video, you probably do not need this method. |
| 689 | * |
| 690 | * @throws RuntimeException if the camera cannot be re-locked (for |
| 691 | * example, if the camera is still in use by another process). |
| 692 | */ |
| 693 | public native final void lock(); |
| 694 | |
| 695 | /** |
| 696 | * Reconnects to the camera service after another process used it. |
| 697 | * After {@link #unlock()} is called, another process may use the |
| 698 | * camera; when the process is done, you must reconnect to the camera, |
| 699 | * which will re-acquire the lock and allow you to continue using the |
| 700 | * camera. |
| 701 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 702 | * <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] | 703 | * {@link android.media.MediaRecorder#start()}. Applications can use the |
| 704 | * camera (ex: zoom) after recording starts. There is no need to call this |
| 705 | * after recording starts or stops. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 706 | * |
| 707 | * <p>If you are not recording video, you probably do not need this method. |
| 708 | * |
| 709 | * @throws IOException if a connection cannot be re-established (for |
| 710 | * example, if the camera is still in use by another process). |
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. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 713 | */ |
| 714 | public native final void reconnect() throws IOException; |
| 715 | |
| 716 | /** |
| 717 | * Sets the {@link Surface} to be used for live preview. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 718 | * Either a surface or surface texture is necessary for preview, and |
| 719 | * preview is necessary to take pictures. The same surface can be re-set |
| 720 | * without harm. Setting a preview surface will un-set any preview surface |
| 721 | * texture that was set via {@link #setPreviewTexture}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 722 | * |
| 723 | * <p>The {@link SurfaceHolder} must already contain a surface when this |
| 724 | * method is called. If you are using {@link android.view.SurfaceView}, |
| 725 | * you will need to register a {@link SurfaceHolder.Callback} with |
| 726 | * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for |
| 727 | * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before |
| 728 | * calling setPreviewDisplay() or starting preview. |
| 729 | * |
| 730 | * <p>This method must be called before {@link #startPreview()}. The |
| 731 | * one exception is that if the preview surface is not set (or set to null) |
| 732 | * before startPreview() is called, then this method may be called once |
| 733 | * with a non-null parameter to set the preview surface. (This allows |
| 734 | * camera setup and surface creation to happen in parallel, saving time.) |
| 735 | * The preview surface may not otherwise change while preview is running. |
| 736 | * |
| 737 | * @param holder containing the Surface on which to place the preview, |
| 738 | * or null to remove the preview surface |
| 739 | * @throws IOException if the method fails (for example, if the surface |
| 740 | * is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 741 | * @throws RuntimeException if release() has been called on this Camera |
| 742 | * instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | */ |
| 744 | public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 745 | if (holder != null) { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 746 | setPreviewSurface(holder.getSurface()); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 747 | } else { |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 748 | setPreviewSurface((Surface)null); |
Wu-cheng Li | b8a10fe | 2009-06-23 23:37:36 +0800 | [diff] [blame] | 749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 752 | /** |
| 753 | * @hide |
| 754 | */ |
Mathew Inwood | 45d2c25 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 755 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Ruben Brunk | feb50af | 2014-05-09 19:58:49 -0700 | [diff] [blame] | 756 | public native final void setPreviewSurface(Surface surface) throws IOException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | |
| 758 | /** |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 759 | * Sets the {@link SurfaceTexture} to be used for live preview. |
| 760 | * Either a surface or surface texture is necessary for preview, and |
| 761 | * preview is necessary to take pictures. The same surface texture can be |
| 762 | * re-set without harm. Setting a preview surface texture will un-set any |
| 763 | * preview surface that was set via {@link #setPreviewDisplay}. |
| 764 | * |
| 765 | * <p>This method must be called before {@link #startPreview()}. The |
| 766 | * one exception is that if the preview surface texture is not set (or set |
| 767 | * to null) before startPreview() is called, then this method may be called |
| 768 | * once with a non-null parameter to set the preview surface. (This allows |
| 769 | * camera setup and surface creation to happen in parallel, saving time.) |
| 770 | * The preview surface texture may not otherwise change while preview is |
| 771 | * running. |
| 772 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 773 | * <p>The timestamps provided by {@link SurfaceTexture#getTimestamp()} for a |
Eino-Ville Talvala | e309a0f | 2011-03-21 11:04:34 -0700 | [diff] [blame] | 774 | * SurfaceTexture set as the preview texture have an unspecified zero point, |
| 775 | * and cannot be directly compared between different cameras or different |
| 776 | * instances of the same camera, or across multiple runs of the same |
| 777 | * program. |
| 778 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 779 | * <p>If you are using the preview data to create video or still images, |
| 780 | * strongly consider using {@link android.media.MediaActionSound} to |
| 781 | * properly indicate image capture or recording start/stop to the user.</p> |
| 782 | * |
| 783 | * @see android.media.MediaActionSound |
| 784 | * @see android.graphics.SurfaceTexture |
| 785 | * @see android.view.TextureView |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 786 | * @param surfaceTexture the {@link SurfaceTexture} to which the preview |
| 787 | * images are to be sent or null to remove the current preview surface |
| 788 | * texture |
| 789 | * @throws IOException if the method fails (for example, if the surface |
| 790 | * texture is unavailable or unsuitable). |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 791 | * @throws RuntimeException if release() has been called on this Camera |
| 792 | * instance. |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 793 | */ |
Glenn Kasten | dbc289d | 2011-02-09 10:15:44 -0800 | [diff] [blame] | 794 | public native final void setPreviewTexture(SurfaceTexture surfaceTexture) throws IOException; |
Jamie Gennis | fd6f39e | 2010-12-20 12:15:00 -0800 | [diff] [blame] | 795 | |
| 796 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 797 | * Callback interface used to deliver copies of preview frames as |
| 798 | * they are displayed. |
| 799 | * |
| 800 | * @see #setPreviewCallback(Camera.PreviewCallback) |
| 801 | * @see #setOneShotPreviewCallback(Camera.PreviewCallback) |
| 802 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 803 | * @see #startPreview() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 804 | * |
| 805 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 806 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 808 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | public interface PreviewCallback |
| 810 | { |
| 811 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 812 | * Called as preview frames are displayed. This callback is invoked |
Dan Egnor | 341ff13 | 2010-07-20 11:30:17 -0700 | [diff] [blame] | 813 | * 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] | 814 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 815 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, |
| 816 | * refer to the equations in {@link Camera.Parameters#setPreviewFormat} |
| 817 | * for the arrangement of the pixel data in the preview callback |
| 818 | * buffers. |
| 819 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 820 | * @param data the contents of the preview frame in the format defined |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 821 | * by {@link android.graphics.ImageFormat}, which can be queried |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 822 | * with {@link android.hardware.Camera.Parameters#getPreviewFormat()}. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 823 | * If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 824 | * is never called, the default will be the YCbCr_420_SP |
| 825 | * (NV21) format. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 826 | * @param camera the Camera service object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | */ |
| 828 | void onPreviewFrame(byte[] data, Camera camera); |
| 829 | }; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 832 | * Starts capturing and drawing preview frames to the screen. |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 833 | * Preview will not actually start until a surface is supplied |
| 834 | * with {@link #setPreviewDisplay(SurfaceHolder)} or |
| 835 | * {@link #setPreviewTexture(SurfaceTexture)}. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 836 | * |
| 837 | * <p>If {@link #setPreviewCallback(Camera.PreviewCallback)}, |
| 838 | * {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or |
| 839 | * {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were |
| 840 | * called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)} |
| 841 | * will be called when preview data becomes available. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 842 | * |
| 843 | * @throws RuntimeException if starting preview fails; usually this would be |
| 844 | * 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] | 845 | * has been called on this Camera instance. The QCIF (176x144) exception |
| 846 | * mentioned in {@link Parameters#setPreviewSize setPreviewSize} and |
| 847 | * {@link Parameters#setPictureSize setPictureSize} can also cause this |
| 848 | * exception be thrown. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | */ |
| 850 | public native final void startPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 853 | * Stops capturing and drawing preview frames to the surface, and |
| 854 | * resets the camera for a future call to {@link #startPreview()}. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 855 | * |
| 856 | * @throws RuntimeException if stopping preview fails; usually this would be |
| 857 | * because of a hardware or other low-level error, or because release() |
| 858 | * has been called on this Camera instance. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | */ |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 860 | public final void stopPreview() { |
| 861 | _stopPreview(); |
| 862 | mFaceDetectionRunning = false; |
Chih-yu Huang | 664d72e | 2011-09-23 18:59:38 +0800 | [diff] [blame] | 863 | |
| 864 | mShutterCallback = null; |
| 865 | mRawImageCallback = null; |
| 866 | mPostviewCallback = null; |
| 867 | mJpegCallback = null; |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 868 | synchronized (mAutoFocusCallbackLock) { |
| 869 | mAutoFocusCallback = null; |
| 870 | } |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 871 | mAutoFocusMoveCallback = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | private native final void _stopPreview(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 875 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | /** |
| 877 | * Return current preview state. |
| 878 | * |
| 879 | * FIXME: Unhide before release |
| 880 | * @hide |
| 881 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 882 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | public native final boolean previewEnabled(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 886 | * <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] | 887 | * to displaying them on the screen. The callback will be repeatedly called |
| 888 | * 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] | 889 | * even while preview is live. Any other preview callbacks are |
| 890 | * overridden.</p> |
| 891 | * |
| 892 | * <p>If you are using the preview data to create video or still images, |
| 893 | * strongly consider using {@link android.media.MediaActionSound} to |
| 894 | * 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] | 895 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 896 | * @param cb a callback object that receives a copy of each preview frame, |
| 897 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 898 | * @throws RuntimeException if release() has been called on this Camera |
| 899 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 900 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | */ |
| 902 | public final void setPreviewCallback(PreviewCallback cb) { |
| 903 | mPreviewCallback = cb; |
| 904 | mOneShot = false; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 905 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 906 | if (cb != null) { |
| 907 | mUsingPreviewAllocation = false; |
| 908 | } |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 909 | // Always use one-shot mode. We fake camera preview mode by |
| 910 | // doing one-shot preview continuously. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 911 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 915 | * <p>Installs a callback to be invoked for the next preview frame in |
| 916 | * addition to displaying it on the screen. After one invocation, the |
| 917 | * callback is cleared. This method can be called any time, even when |
| 918 | * preview is live. Any other preview callbacks are overridden.</p> |
| 919 | * |
| 920 | * <p>If you are using the preview data to create video or still images, |
| 921 | * strongly consider using {@link android.media.MediaActionSound} to |
| 922 | * 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] | 923 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 924 | * @param cb a callback object that receives a copy of the next preview frame, |
| 925 | * or null to stop receiving callbacks. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 926 | * @throws RuntimeException if release() has been called on this Camera |
| 927 | * instance. |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 928 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | */ |
| 930 | public final void setOneShotPreviewCallback(PreviewCallback cb) { |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 931 | mPreviewCallback = cb; |
| 932 | mOneShot = true; |
| 933 | mWithBuffer = false; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 934 | if (cb != null) { |
| 935 | mUsingPreviewAllocation = false; |
| 936 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 937 | setHasPreviewCallback(cb != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 940 | private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer); |
| 941 | |
| 942 | /** |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 943 | * <p>Installs a callback to be invoked for every preview frame, using |
| 944 | * buffers supplied with {@link #addCallbackBuffer(byte[])}, in addition to |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 945 | * displaying them on the screen. The callback will be repeatedly called |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 946 | * for as long as preview is active and buffers are available. Any other |
| 947 | * preview callbacks are overridden.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 948 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 949 | * <p>The purpose of this method is to improve preview efficiency and frame |
| 950 | * rate by allowing preview frame memory reuse. You must call |
| 951 | * {@link #addCallbackBuffer(byte[])} at some point -- before or after |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 952 | * calling this method -- or no callbacks will received.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 953 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 954 | * <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] | 955 | * callback, {@link #setPreviewCallback(Camera.PreviewCallback)} is called, |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 956 | * or {@link #setOneShotPreviewCallback(Camera.PreviewCallback)} is |
| 957 | * called.</p> |
| 958 | * |
| 959 | * <p>If you are using the preview data to create video or still images, |
| 960 | * strongly consider using {@link android.media.MediaActionSound} to |
| 961 | * properly indicate image capture or recording start/stop to the user.</p> |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 962 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 963 | * @param cb a callback object that receives a copy of the preview frame, |
| 964 | * or null to stop receiving callbacks and clear the buffer queue. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 965 | * @throws RuntimeException if release() has been called on this Camera |
| 966 | * instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 967 | * @see #addCallbackBuffer(byte[]) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 968 | * @see android.media.MediaActionSound |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 969 | */ |
| 970 | public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { |
| 971 | mPreviewCallback = cb; |
| 972 | mOneShot = false; |
| 973 | mWithBuffer = true; |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 974 | if (cb != null) { |
| 975 | mUsingPreviewAllocation = false; |
| 976 | } |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 977 | setHasPreviewCallback(cb != null, true); |
| 978 | } |
| 979 | |
| 980 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 981 | * Adds a pre-allocated buffer to the preview callback buffer queue. |
| 982 | * 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] | 983 | * frame arrives and there is still at least one available buffer, the |
| 984 | * buffer will be used and removed from the queue. Then preview callback is |
| 985 | * invoked with the buffer. If a frame arrives and there is no buffer left, |
| 986 | * the frame is discarded. Applications should add buffers back when they |
| 987 | * finish processing the data in them. |
Wu-cheng Li | c10275a | 2010-03-09 13:49:21 -0800 | [diff] [blame] | 988 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 989 | * <p>For formats besides YV12, the size of the buffer is determined by |
| 990 | * multiplying the preview image width, height, and bytes per pixel. The |
| 991 | * width and height can be read from |
| 992 | * {@link Camera.Parameters#getPreviewSize()}. Bytes per pixel can be |
| 993 | * computed from {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / |
| 994 | * 8, using the image format from |
| 995 | * {@link Camera.Parameters#getPreviewFormat()}. |
| 996 | * |
| 997 | * <p>If using the {@link android.graphics.ImageFormat#YV12} format, the |
| 998 | * size can be calculated using the equations listed in |
| 999 | * {@link Camera.Parameters#setPreviewFormat}. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1000 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1001 | * <p>This method is only necessary when |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1002 | * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1003 | * {@link #setPreviewCallback(PreviewCallback)} or |
| 1004 | * {@link #setOneShotPreviewCallback(PreviewCallback)} are used, buffers |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1005 | * are automatically allocated. When a supplied buffer is too small to |
| 1006 | * hold the preview frame data, preview callback will return null and |
| 1007 | * the buffer will be removed from the buffer queue. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1008 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 1009 | * @param callbackBuffer the buffer to add to the queue. The size of the |
| 1010 | * buffer must match the values described above. |
Wu-cheng Li | 5b9bcda | 2010-03-07 14:59:28 -0800 | [diff] [blame] | 1011 | * @see #setPreviewCallbackWithBuffer(PreviewCallback) |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1012 | */ |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1013 | public final void addCallbackBuffer(byte[] callbackBuffer) |
| 1014 | { |
| 1015 | _addCallbackBuffer(callbackBuffer, CAMERA_MSG_PREVIEW_FRAME); |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Adds a pre-allocated buffer to the raw image callback buffer queue. |
| 1020 | * Applications can add one or more buffers to the queue. When a raw image |
| 1021 | * frame arrives and there is still at least one available buffer, the |
| 1022 | * buffer will be used to hold the raw image data and removed from the |
| 1023 | * queue. Then raw image callback is invoked with the buffer. If a raw |
| 1024 | * image frame arrives but there is no buffer left, the frame is |
| 1025 | * discarded. Applications should add buffers back when they finish |
| 1026 | * processing the data in them by calling this method again in order |
| 1027 | * to avoid running out of raw image callback buffers. |
| 1028 | * |
| 1029 | * <p>The size of the buffer is determined by multiplying the raw image |
| 1030 | * width, height, and bytes per pixel. The width and height can be |
| 1031 | * read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel |
| 1032 | * can be computed from |
| 1033 | * {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8, |
| 1034 | * using the image format from {@link Camera.Parameters#getPreviewFormat()}. |
| 1035 | * |
| 1036 | * <p>This method is only necessary when the PictureCallbck for raw image |
| 1037 | * is used while calling {@link #takePicture(Camera.ShutterCallback, |
| 1038 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 1039 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 1040 | * <p>Please note that by calling this method, the mode for |
| 1041 | * application-managed callback buffers is triggered. If this method has |
| 1042 | * never been called, null will be returned by the raw image callback since |
| 1043 | * there is no image callback buffer available. Furthermore, When a supplied |
| 1044 | * buffer is too small to hold the raw image data, raw image callback will |
| 1045 | * return null and the buffer will be removed from the buffer queue. |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1046 | * |
| 1047 | * @param callbackBuffer the buffer to add to the raw image callback buffer |
| 1048 | * queue. The size should be width * height * (bits per pixel) / 8. An |
| 1049 | * null callbackBuffer will be ignored and won't be added to the queue. |
| 1050 | * |
| 1051 | * @see #takePicture(Camera.ShutterCallback, |
| 1052 | * Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}. |
| 1053 | * |
| 1054 | * {@hide} |
| 1055 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 1056 | @UnsupportedAppUsage |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1057 | public final void addRawImageCallbackBuffer(byte[] callbackBuffer) |
| 1058 | { |
| 1059 | addCallbackBuffer(callbackBuffer, CAMERA_MSG_RAW_IMAGE); |
| 1060 | } |
| 1061 | |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 1062 | @UnsupportedAppUsage |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1063 | private final void addCallbackBuffer(byte[] callbackBuffer, int msgType) |
| 1064 | { |
| 1065 | // CAMERA_MSG_VIDEO_FRAME may be allowed in the future. |
| 1066 | if (msgType != CAMERA_MSG_PREVIEW_FRAME && |
| 1067 | msgType != CAMERA_MSG_RAW_IMAGE) { |
| 1068 | throw new IllegalArgumentException( |
| 1069 | "Unsupported message type: " + msgType); |
| 1070 | } |
| 1071 | |
| 1072 | _addCallbackBuffer(callbackBuffer, msgType); |
| 1073 | } |
| 1074 | |
| 1075 | private native final void _addCallbackBuffer( |
| 1076 | byte[] callbackBuffer, int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 1078 | /** |
| 1079 | * <p>Create a {@link android.renderscript RenderScript} |
| 1080 | * {@link android.renderscript.Allocation Allocation} to use as a |
| 1081 | * destination of preview callback frames. Use |
| 1082 | * {@link #setPreviewCallbackAllocation setPreviewCallbackAllocation} to use |
| 1083 | * the created Allocation as a destination for camera preview frames.</p> |
| 1084 | * |
| 1085 | * <p>The Allocation will be created with a YUV type, and its contents must |
| 1086 | * be accessed within Renderscript with the {@code rsGetElementAtYuv_*} |
| 1087 | * accessor methods. Its size will be based on the current |
| 1088 | * {@link Parameters#getPreviewSize preview size} configured for this |
| 1089 | * camera.</p> |
| 1090 | * |
| 1091 | * @param rs the RenderScript context for this Allocation. |
| 1092 | * @param usage additional usage flags to set for the Allocation. The usage |
| 1093 | * flag {@link android.renderscript.Allocation#USAGE_IO_INPUT} will always |
| 1094 | * be set on the created Allocation, but additional flags may be provided |
| 1095 | * here. |
| 1096 | * @return a new YUV-type Allocation with dimensions equal to the current |
| 1097 | * preview size. |
| 1098 | * @throws RSIllegalArgumentException if the usage flags are not compatible |
| 1099 | * with an YUV Allocation. |
| 1100 | * @see #setPreviewCallbackAllocation |
| 1101 | * @hide |
| 1102 | */ |
| 1103 | public final Allocation createPreviewAllocation(RenderScript rs, int usage) |
| 1104 | throws RSIllegalArgumentException { |
| 1105 | Parameters p = getParameters(); |
| 1106 | Size previewSize = p.getPreviewSize(); |
| 1107 | Type.Builder yuvBuilder = new Type.Builder(rs, |
| 1108 | Element.createPixel(rs, |
| 1109 | Element.DataType.UNSIGNED_8, |
| 1110 | Element.DataKind.PIXEL_YUV)); |
| 1111 | // Use YV12 for wide compatibility. Changing this requires also |
| 1112 | // adjusting camera service's format selection. |
| 1113 | yuvBuilder.setYuvFormat(ImageFormat.YV12); |
| 1114 | yuvBuilder.setX(previewSize.width); |
| 1115 | yuvBuilder.setY(previewSize.height); |
| 1116 | |
| 1117 | Allocation a = Allocation.createTyped(rs, yuvBuilder.create(), |
| 1118 | usage | Allocation.USAGE_IO_INPUT); |
| 1119 | |
| 1120 | return a; |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * <p>Set an {@link android.renderscript.Allocation Allocation} as the |
| 1125 | * target of preview callback data. Use this method for efficient processing |
| 1126 | * of camera preview data with RenderScript. The Allocation must be created |
| 1127 | * with the {@link #createPreviewAllocation createPreviewAllocation } |
| 1128 | * method.</p> |
| 1129 | * |
| 1130 | * <p>Setting a preview allocation will disable any active preview callbacks |
| 1131 | * set by {@link #setPreviewCallback setPreviewCallback} or |
| 1132 | * {@link #setPreviewCallbackWithBuffer setPreviewCallbackWithBuffer}, and |
| 1133 | * vice versa. Using a preview allocation still requires an active standard |
| 1134 | * preview target to be set, either with |
| 1135 | * {@link #setPreviewTexture setPreviewTexture} or |
| 1136 | * {@link #setPreviewDisplay setPreviewDisplay}.</p> |
| 1137 | * |
| 1138 | * <p>To be notified when new frames are available to the Allocation, use |
| 1139 | * {@link android.renderscript.Allocation#setIoInputNotificationHandler Allocation.setIoInputNotificationHandler}. To |
| 1140 | * update the frame currently accessible from the Allocation to the latest |
| 1141 | * preview frame, call |
| 1142 | * {@link android.renderscript.Allocation#ioReceive Allocation.ioReceive}.</p> |
| 1143 | * |
| 1144 | * <p>To disable preview into the Allocation, call this method with a |
| 1145 | * {@code null} parameter.</p> |
| 1146 | * |
| 1147 | * <p>Once a preview allocation is set, the preview size set by |
| 1148 | * {@link Parameters#setPreviewSize setPreviewSize} cannot be changed. If |
| 1149 | * you wish to change the preview size, first remove the preview allocation |
| 1150 | * by calling {@code setPreviewCallbackAllocation(null)}, then change the |
| 1151 | * preview size, create a new preview Allocation with |
| 1152 | * {@link #createPreviewAllocation createPreviewAllocation}, and set it as |
| 1153 | * the new preview callback allocation target.</p> |
| 1154 | * |
| 1155 | * <p>If you are using the preview data to create video or still images, |
| 1156 | * strongly consider using {@link android.media.MediaActionSound} to |
| 1157 | * properly indicate image capture or recording start/stop to the user.</p> |
| 1158 | * |
| 1159 | * @param previewAllocation the allocation to use as destination for preview |
| 1160 | * @throws IOException if configuring the camera to use the Allocation for |
| 1161 | * preview fails. |
| 1162 | * @throws IllegalArgumentException if the Allocation's dimensions or other |
| 1163 | * parameters don't meet the requirements. |
| 1164 | * @see #createPreviewAllocation |
| 1165 | * @see #setPreviewCallback |
| 1166 | * @see #setPreviewCallbackWithBuffer |
| 1167 | * @hide |
| 1168 | */ |
| 1169 | public final void setPreviewCallbackAllocation(Allocation previewAllocation) |
| 1170 | throws IOException { |
| 1171 | Surface previewSurface = null; |
| 1172 | if (previewAllocation != null) { |
| 1173 | Parameters p = getParameters(); |
| 1174 | Size previewSize = p.getPreviewSize(); |
| 1175 | if (previewSize.width != previewAllocation.getType().getX() || |
| 1176 | previewSize.height != previewAllocation.getType().getY()) { |
| 1177 | throw new IllegalArgumentException( |
| 1178 | "Allocation dimensions don't match preview dimensions: " + |
| 1179 | "Allocation is " + |
| 1180 | previewAllocation.getType().getX() + |
| 1181 | ", " + |
| 1182 | previewAllocation.getType().getY() + |
| 1183 | ". Preview is " + previewSize.width + ", " + |
| 1184 | previewSize.height); |
| 1185 | } |
| 1186 | if ((previewAllocation.getUsage() & |
| 1187 | Allocation.USAGE_IO_INPUT) == 0) { |
| 1188 | throw new IllegalArgumentException( |
| 1189 | "Allocation usage does not include USAGE_IO_INPUT"); |
| 1190 | } |
| 1191 | if (previewAllocation.getType().getElement().getDataKind() != |
| 1192 | Element.DataKind.PIXEL_YUV) { |
| 1193 | throw new IllegalArgumentException( |
| 1194 | "Allocation is not of a YUV type"); |
| 1195 | } |
| 1196 | previewSurface = previewAllocation.getSurface(); |
| 1197 | mUsingPreviewAllocation = true; |
| 1198 | } else { |
| 1199 | mUsingPreviewAllocation = false; |
| 1200 | } |
| 1201 | setPreviewCallbackSurface(previewSurface); |
| 1202 | } |
| 1203 | |
| 1204 | private native final void setPreviewCallbackSurface(Surface s); |
| 1205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | private class EventHandler extends Handler |
| 1207 | { |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 1208 | private final Camera mCamera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | |
David Brazdil | 982df3b | 2019-03-07 17:41:03 +0000 | [diff] [blame] | 1210 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | public EventHandler(Camera c, Looper looper) { |
| 1212 | super(looper); |
| 1213 | mCamera = c; |
| 1214 | } |
| 1215 | |
| 1216 | @Override |
| 1217 | public void handleMessage(Message msg) { |
| 1218 | switch(msg.what) { |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1219 | case CAMERA_MSG_SHUTTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | if (mShutterCallback != null) { |
| 1221 | mShutterCallback.onShutter(); |
| 1222 | } |
| 1223 | return; |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1224 | |
| 1225 | case CAMERA_MSG_RAW_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1226 | if (mRawImageCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1228 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | return; |
| 1230 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1231 | case CAMERA_MSG_COMPRESSED_IMAGE: |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1232 | if (mJpegCallback != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1236 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1237 | case CAMERA_MSG_PREVIEW_FRAME: |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1238 | PreviewCallback pCb = mPreviewCallback; |
| 1239 | if (pCb != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | if (mOneShot) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1241 | // Clear the callback variable before the callback |
| 1242 | // in case the app calls setPreviewCallback from |
| 1243 | // the callback function |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | mPreviewCallback = null; |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1245 | } else if (!mWithBuffer) { |
Dave Sparks | a6118c6 | 2009-10-13 02:28:54 -0700 | [diff] [blame] | 1246 | // We're faking the camera preview mode to prevent |
| 1247 | // the app from being flooded with preview frames. |
| 1248 | // Set to oneshot mode again. |
Andrew Harp | 94927df | 2009-10-20 01:47:05 -0400 | [diff] [blame] | 1249 | setHasPreviewCallback(true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | } |
Eino-Ville Talvala | ca367b7 | 2012-05-30 16:01:33 -0700 | [diff] [blame] | 1251 | pCb.onPreviewFrame((byte[])msg.obj, mCamera); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | } |
| 1253 | return; |
| 1254 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1255 | case CAMERA_MSG_POSTVIEW_FRAME: |
| 1256 | if (mPostviewCallback != null) { |
| 1257 | mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera); |
| 1258 | } |
| 1259 | return; |
| 1260 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1261 | case CAMERA_MSG_FOCUS: |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1262 | AutoFocusCallback cb = null; |
| 1263 | synchronized (mAutoFocusCallbackLock) { |
| 1264 | cb = mAutoFocusCallback; |
| 1265 | } |
| 1266 | if (cb != null) { |
| 1267 | boolean success = msg.arg1 == 0 ? false : true; |
| 1268 | cb.onAutoFocus(success, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1269 | } |
| 1270 | return; |
| 1271 | |
| 1272 | case CAMERA_MSG_ZOOM: |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1273 | if (mZoomListener != null) { |
| 1274 | mZoomListener.onZoomChange(msg.arg1, msg.arg2 != 0, mCamera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | return; |
| 1277 | |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1278 | case CAMERA_MSG_PREVIEW_METADATA: |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1279 | if (mFaceListener != null) { |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1280 | mFaceListener.onFaceDetection((Face[])msg.obj, mCamera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1281 | } |
| 1282 | return; |
| 1283 | |
Dave Sparks | c62f9bd | 2009-06-26 13:33:32 -0700 | [diff] [blame] | 1284 | case CAMERA_MSG_ERROR : |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | Log.e(TAG, "Error " + msg.arg1); |
Yin-Chia Yeh | a07cd32 | 2018-05-31 12:11:42 -0700 | [diff] [blame] | 1286 | if (mDetailedErrorCallback != null) { |
| 1287 | mDetailedErrorCallback.onError(msg.arg1, mCamera); |
| 1288 | } else if (mErrorCallback != null) { |
| 1289 | if (msg.arg1 == CAMERA_ERROR_DISABLED) { |
| 1290 | mErrorCallback.onError(CAMERA_ERROR_EVICTED, mCamera); |
| 1291 | } else { |
| 1292 | mErrorCallback.onError(msg.arg1, mCamera); |
| 1293 | } |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | return; |
| 1296 | |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1297 | case CAMERA_MSG_FOCUS_MOVE: |
| 1298 | if (mAutoFocusMoveCallback != null) { |
| 1299 | mAutoFocusMoveCallback.onAutoFocusMoving(msg.arg1 == 0 ? false : true, mCamera); |
| 1300 | } |
| 1301 | return; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 1302 | /* ### QC ADD-ONS: START */ |
| 1303 | case CAMERA_MSG_STATS_DATA: |
| 1304 | int statsdata[] = new int[257]; |
| 1305 | for(int i =0; i<257; i++ ) { |
| 1306 | statsdata[i] = byteToInt( (byte[])msg.obj, i*4); |
| 1307 | } |
| 1308 | if (mCameraDataCallback != null) { |
| 1309 | mCameraDataCallback.onCameraData(statsdata, mCamera); |
| 1310 | } |
| 1311 | return; |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1312 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 1313 | case CAMERA_MSG_META_DATA: |
| 1314 | if (mCameraMetaDataCallback != null) { |
| 1315 | mCameraMetaDataCallback.onCameraMetaData((byte[])msg.obj, mCamera); |
| 1316 | } |
| 1317 | return; |
| 1318 | /* ### QC ADD-ONS: END */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | default: |
| 1320 | Log.e(TAG, "Unknown message type " + msg.what); |
| 1321 | return; |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 1326 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | private static void postEventFromNative(Object camera_ref, |
| 1328 | int what, int arg1, int arg2, Object obj) |
| 1329 | { |
| 1330 | Camera c = (Camera)((WeakReference)camera_ref).get(); |
| 1331 | if (c == null) |
| 1332 | return; |
| 1333 | |
| 1334 | if (c.mEventHandler != null) { |
| 1335 | Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); |
| 1336 | c.mEventHandler.sendMessage(m); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1341 | * Callback interface used to notify on completion of camera auto focus. |
| 1342 | * |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1343 | * <p>Devices that do not support auto-focus will receive a "fake" |
| 1344 | * callback to this interface. If your application needs auto-focus and |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1345 | * should not be installed on devices <em>without</em> auto-focus, you must |
| 1346 | * declare that your app uses the |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1347 | * {@code android.hardware.camera.autofocus} feature, in the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1348 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1349 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1350 | * |
| 1351 | * @see #autoFocus(AutoFocusCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1352 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1353 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1355 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | public interface AutoFocusCallback |
| 1357 | { |
| 1358 | /** |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1359 | * Called when the camera auto focus completes. If the camera |
| 1360 | * does not support auto-focus and autoFocus is called, |
| 1361 | * onAutoFocus will be called immediately with a fake value of |
| 1362 | * <code>success</code> set to <code>true</code>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1363 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1364 | * The auto-focus routine does not lock auto-exposure and auto-white |
| 1365 | * balance after it completes. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1366 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | * @param success true if focus was successful, false if otherwise |
| 1368 | * @param camera the Camera service object |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1369 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1370 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | */ |
| 1372 | void onAutoFocus(boolean success, Camera camera); |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | |
| 1375 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1376 | * Starts camera auto-focus and registers a callback function to run when |
| 1377 | * the camera is focused. This method is only valid when preview is active |
| 1378 | * (between {@link #startPreview()} and before {@link #stopPreview()}). |
| 1379 | * |
| 1380 | * <p>Callers should check |
| 1381 | * {@link android.hardware.Camera.Parameters#getFocusMode()} to determine if |
| 1382 | * this method should be called. If the camera does not support auto-focus, |
| 1383 | * it is a no-op and {@link AutoFocusCallback#onAutoFocus(boolean, Camera)} |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 1384 | * callback will be called immediately. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1385 | * |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 1386 | * <p>If your application should not be installed |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 1387 | * on devices without auto-focus, you must declare that your application |
| 1388 | * uses auto-focus with the |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 1389 | * <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><uses-feature></a> |
| 1390 | * manifest element.</p> |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1391 | * |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 1392 | * <p>If the current flash mode is not |
| 1393 | * {@link android.hardware.Camera.Parameters#FLASH_MODE_OFF}, flash may be |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1394 | * 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] | 1395 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1396 | * <p>Auto-exposure lock {@link android.hardware.Camera.Parameters#getAutoExposureLock()} |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 1397 | * and auto-white balance locks {@link android.hardware.Camera.Parameters#getAutoWhiteBalanceLock()} |
| 1398 | * do not change during and after autofocus. But auto-focus routine may stop |
| 1399 | * auto-exposure and auto-white balance transiently during focusing. |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1400 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1401 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 1402 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
| 1403 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 1404 | * the focus position. Applications must call cancelAutoFocus to reset the |
| 1405 | * focus.</p> |
| 1406 | * |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1407 | * <p>If autofocus is successful, consider using |
| 1408 | * {@link android.media.MediaActionSound} to properly play back an autofocus |
| 1409 | * success sound to the user.</p> |
| 1410 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1412 | * @throws RuntimeException if starting autofocus fails; usually this would |
| 1413 | * be because of a hardware or other low-level error, or because |
| 1414 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1415 | * @see #cancelAutoFocus() |
Eino-Ville Talvala | 83d3352 | 2011-05-13 10:25:00 -0700 | [diff] [blame] | 1416 | * @see android.hardware.Camera.Parameters#setAutoExposureLock(boolean) |
| 1417 | * @see android.hardware.Camera.Parameters#setAutoWhiteBalanceLock(boolean) |
Eino-Ville Talvala | 108708b | 2012-03-05 11:00:43 -0800 | [diff] [blame] | 1418 | * @see android.media.MediaActionSound |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | */ |
| 1420 | public final void autoFocus(AutoFocusCallback cb) |
| 1421 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1422 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1423 | mAutoFocusCallback = cb; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1424 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1425 | native_autoFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | } |
| 1427 | private native final void native_autoFocus(); |
| 1428 | |
| 1429 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1430 | * Cancels any auto-focus function in progress. |
| 1431 | * Whether or not auto-focus is currently in progress, |
| 1432 | * this function will return the focus position to the default. |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1433 | * 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] | 1434 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1435 | * @throws RuntimeException if canceling autofocus fails; usually this would |
| 1436 | * be because of a hardware or other low-level error, or because |
| 1437 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1438 | * @see #autoFocus(Camera.AutoFocusCallback) |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1439 | */ |
| 1440 | public final void cancelAutoFocus() |
| 1441 | { |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1442 | synchronized (mAutoFocusCallbackLock) { |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1443 | mAutoFocusCallback = null; |
James Dong | 248ba23 | 2012-04-28 21:30:46 -0700 | [diff] [blame] | 1444 | } |
Wu-cheng Li | f05c1d6 | 2012-05-02 23:29:47 +0800 | [diff] [blame] | 1445 | native_cancelAutoFocus(); |
| 1446 | // CAMERA_MSG_FOCUS should be removed here because the following |
| 1447 | // scenario can happen: |
| 1448 | // - An application uses the same thread for autoFocus, cancelAutoFocus |
| 1449 | // and looper thread. |
| 1450 | // - The application calls autoFocus. |
| 1451 | // - HAL sends CAMERA_MSG_FOCUS, which enters the looper message queue. |
| 1452 | // Before event handler's handleMessage() is invoked, the application |
| 1453 | // calls cancelAutoFocus and autoFocus. |
| 1454 | // - The application gets the old CAMERA_MSG_FOCUS and thinks autofocus |
| 1455 | // has been completed. But in fact it is not. |
| 1456 | // |
| 1457 | // As documented in the beginning of the file, apps should not use |
| 1458 | // multiple threads to call autoFocus and cancelAutoFocus at the same |
| 1459 | // time. It is HAL's responsibility not to send a CAMERA_MSG_FOCUS |
| 1460 | // message after native_cancelAutoFocus is called. |
| 1461 | mEventHandler.removeMessages(CAMERA_MSG_FOCUS); |
Chih-Chung Chang | 244f8c2 | 2009-09-15 14:51:56 +0800 | [diff] [blame] | 1462 | } |
| 1463 | private native final void native_cancelAutoFocus(); |
| 1464 | |
| 1465 | /** |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1466 | * Callback interface used to notify on auto focus start and stop. |
| 1467 | * |
Wu-cheng Li | 6574539 | 2012-04-12 18:07:16 +0800 | [diff] [blame] | 1468 | * <p>This is only supported in continuous autofocus modes -- {@link |
| 1469 | * Parameters#FOCUS_MODE_CONTINUOUS_VIDEO} and {@link |
| 1470 | * Parameters#FOCUS_MODE_CONTINUOUS_PICTURE}. Applications can show |
| 1471 | * autofocus animation based on this.</p> |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1472 | * |
| 1473 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1474 | * applications. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1475 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1476 | @Deprecated |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1477 | public interface AutoFocusMoveCallback |
| 1478 | { |
| 1479 | /** |
| 1480 | * Called when the camera auto focus starts or stops. |
| 1481 | * |
| 1482 | * @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] | 1483 | * @param camera the Camera service object |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1484 | */ |
| 1485 | void onAutoFocusMoving(boolean start, Camera camera); |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Sets camera auto-focus move callback. |
| 1490 | * |
| 1491 | * @param cb the callback to run |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1492 | * @throws RuntimeException if enabling the focus move callback fails; |
| 1493 | * usually this would be because of a hardware or other low-level error, |
| 1494 | * or because release() has been called on this Camera instance. |
Wu-cheng Li | 9d062cf | 2011-11-14 20:30:14 +0800 | [diff] [blame] | 1495 | */ |
| 1496 | public void setAutoFocusMoveCallback(AutoFocusMoveCallback cb) { |
| 1497 | mAutoFocusMoveCallback = cb; |
| 1498 | enableFocusMoveCallback((mAutoFocusMoveCallback != null) ? 1 : 0); |
| 1499 | } |
| 1500 | |
| 1501 | private native void enableFocusMoveCallback(int enable); |
| 1502 | |
| 1503 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1504 | * Callback interface used to signal the moment of actual image capture. |
| 1505 | * |
| 1506 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1507 | * |
| 1508 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1509 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1511 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | public interface ShutterCallback |
| 1513 | { |
| 1514 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1515 | * Called as near as possible to the moment when a photo is captured |
| 1516 | * from the sensor. This is a good opportunity to play a shutter sound |
| 1517 | * or give other feedback of camera operation. This may be some time |
| 1518 | * after the photo was triggered, but some time before the actual data |
| 1519 | * is available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | */ |
| 1521 | void onShutter(); |
| 1522 | } |
| 1523 | |
| 1524 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1525 | * Callback interface used to supply image data from a photo capture. |
| 1526 | * |
| 1527 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1528 | * |
| 1529 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1530 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1532 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | public interface PictureCallback { |
| 1534 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1535 | * Called when image data is available after a picture is taken. |
| 1536 | * The format of the data depends on the context of the callback |
| 1537 | * and {@link Camera.Parameters} settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1538 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | * @param data a byte array of the picture data |
| 1540 | * @param camera the Camera service object |
| 1541 | */ |
| 1542 | void onPictureTaken(byte[] data, Camera camera); |
| 1543 | }; |
| 1544 | |
| 1545 | /** |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1546 | * Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1547 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1548 | * @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | */ |
| 1550 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1551 | PictureCallback jpeg) { |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1552 | takePicture(shutter, raw, null, jpeg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | } |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1554 | private native final void native_takePicture(int msgType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1556 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1557 | * Triggers an asynchronous image capture. The camera service will initiate |
| 1558 | * a series of callbacks to the application as the image capture progresses. |
| 1559 | * The shutter callback occurs after the image is captured. This can be used |
| 1560 | * to trigger a sound to let the user know that image has been captured. The |
| 1561 | * 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] | 1562 | * will be null if there is no raw image callback buffer available or the |
| 1563 | * 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] | 1564 | * The postview callback occurs when a scaled, fully processed postview |
| 1565 | * image is available (NOTE: not all hardware supports this). The jpeg |
| 1566 | * callback occurs when the compressed image is available. If the |
| 1567 | * application does not need a particular callback, a null can be passed |
| 1568 | * instead of a callback method. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1569 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1570 | * <p>This method is only valid when preview is active (after |
| 1571 | * {@link #startPreview()}). Preview will be stopped after the image is |
| 1572 | * taken; callers must call {@link #startPreview()} again if they want to |
Wu-cheng Li | 42419ce | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 1573 | * re-start preview or take more pictures. This should not be called between |
| 1574 | * {@link android.media.MediaRecorder#start()} and |
| 1575 | * {@link android.media.MediaRecorder#stop()}. |
Wu-cheng Li | 40057ce | 2009-12-02 18:57:29 +0800 | [diff] [blame] | 1576 | * |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1577 | * <p>After calling this method, you must not call {@link #startPreview()} |
| 1578 | * or take another picture until the JPEG callback has returned. |
| 1579 | * |
| 1580 | * @param shutter the callback for image capture moment, or null |
| 1581 | * @param raw the callback for raw (uncompressed) image data, or null |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1582 | * @param postview callback with postview image data, may be null |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1583 | * @param jpeg the callback for JPEG image data, or null |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1584 | * @throws RuntimeException if starting picture capture fails; usually this |
| 1585 | * would be because of a hardware or other low-level error, or because |
| 1586 | * release() has been called on this Camera instance. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1587 | */ |
| 1588 | public final void takePicture(ShutterCallback shutter, PictureCallback raw, |
| 1589 | PictureCallback postview, PictureCallback jpeg) { |
| 1590 | mShutterCallback = shutter; |
| 1591 | mRawImageCallback = raw; |
| 1592 | mPostviewCallback = postview; |
| 1593 | mJpegCallback = jpeg; |
James Dong | e00cab7 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 1594 | |
| 1595 | // If callback is not set, do not send me callbacks. |
| 1596 | int msgType = 0; |
| 1597 | if (mShutterCallback != null) { |
| 1598 | msgType |= CAMERA_MSG_SHUTTER; |
| 1599 | } |
| 1600 | if (mRawImageCallback != null) { |
| 1601 | msgType |= CAMERA_MSG_RAW_IMAGE; |
| 1602 | } |
| 1603 | if (mPostviewCallback != null) { |
| 1604 | msgType |= CAMERA_MSG_POSTVIEW_FRAME; |
| 1605 | } |
| 1606 | if (mJpegCallback != null) { |
| 1607 | msgType |= CAMERA_MSG_COMPRESSED_IMAGE; |
| 1608 | } |
| 1609 | |
| 1610 | native_takePicture(msgType); |
Wu-cheng Li | e9c6c9c | 2012-05-29 16:47:44 +0800 | [diff] [blame] | 1611 | mFaceDetectionRunning = false; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1615 | * Zooms to the requested value smoothly. The driver will notify {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1616 | * OnZoomChangeListener} of the zoom value and whether zoom is stopped at |
| 1617 | * the time. For example, suppose the current zoom is 0 and startSmoothZoom |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1618 | * is called with value 3. The |
| 1619 | * {@link Camera.OnZoomChangeListener#onZoomChange(int, boolean, Camera)} |
| 1620 | * method will be called three times with zoom values 1, 2, and 3. |
| 1621 | * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. |
| 1622 | * Applications should not call startSmoothZoom again or change the zoom |
| 1623 | * value before zoom stops. If the supplied zoom value equals to the current |
| 1624 | * zoom value, no zoom callback will be generated. This method is supported |
| 1625 | * if {@link android.hardware.Camera.Parameters#isSmoothZoomSupported} |
| 1626 | * returns true. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1627 | * |
| 1628 | * @param value zoom value. The valid range is 0 to {@link |
| 1629 | * android.hardware.Camera.Parameters#getMaxZoom}. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1630 | * @throws IllegalArgumentException if the zoom value is invalid. |
| 1631 | * @throws RuntimeException if the method fails. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1632 | * @see #setZoomChangeListener(OnZoomChangeListener) |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1633 | */ |
| 1634 | public native final void startSmoothZoom(int value); |
| 1635 | |
| 1636 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1637 | * Stops the smooth zoom. Applications should wait for the {@link |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1638 | * OnZoomChangeListener} to know when the zoom is actually stopped. This |
| 1639 | * method is supported if {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1640 | * android.hardware.Camera.Parameters#isSmoothZoomSupported} is true. |
Wu-cheng Li | 0ca2519 | 2010-03-29 16:21:12 +0800 | [diff] [blame] | 1641 | * |
| 1642 | * @throws RuntimeException if the method fails. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1643 | */ |
| 1644 | public native final void stopSmoothZoom(); |
| 1645 | |
| 1646 | /** |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1647 | * Set the clockwise rotation of preview display in degrees. This affects |
| 1648 | * the preview frames and the picture displayed after snapshot. This method |
| 1649 | * is useful for portrait mode applications. Note that preview display of |
Wu-cheng Li | b982fb4 | 2010-10-19 17:19:09 +0800 | [diff] [blame] | 1650 | * front-facing cameras is flipped horizontally before the rotation, that |
| 1651 | * is, the image is reflected along the central vertical axis of the camera |
| 1652 | * 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] | 1653 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1654 | * <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] | 1655 | * PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded videos. This |
| 1656 | * method is not allowed to be called during preview. |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1657 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 1658 | * <p>If you want to make the camera image show in the same orientation as |
| 1659 | * the display, you can use the following code. |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1660 | * <pre> |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1661 | * public static void setCameraDisplayOrientation(Activity activity, |
| 1662 | * int cameraId, android.hardware.Camera camera) { |
| 1663 | * android.hardware.Camera.CameraInfo info = |
| 1664 | * new android.hardware.Camera.CameraInfo(); |
| 1665 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 1666 | * int rotation = activity.getWindowManager().getDefaultDisplay() |
| 1667 | * .getRotation(); |
| 1668 | * int degrees = 0; |
| 1669 | * switch (rotation) { |
| 1670 | * case Surface.ROTATION_0: degrees = 0; break; |
| 1671 | * case Surface.ROTATION_90: degrees = 90; break; |
| 1672 | * case Surface.ROTATION_180: degrees = 180; break; |
| 1673 | * case Surface.ROTATION_270: degrees = 270; break; |
| 1674 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1675 | * |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1676 | * int result; |
| 1677 | * if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { |
| 1678 | * result = (info.orientation + degrees) % 360; |
| 1679 | * result = (360 - result) % 360; // compensate the mirror |
| 1680 | * } else { // back-facing |
| 1681 | * result = (info.orientation - degrees + 360) % 360; |
| 1682 | * } |
Chih-Chung Chang | 724c522 | 2010-06-14 18:57:15 +0800 | [diff] [blame] | 1683 | * camera.setDisplayOrientation(result); |
| 1684 | * } |
Chih-Chung Chang | b8bb78f | 2010-06-10 13:32:16 +0800 | [diff] [blame] | 1685 | * </pre> |
Wu-cheng Li | d303362 | 2011-10-07 13:13:54 +0800 | [diff] [blame] | 1686 | * |
| 1687 | * <p>Starting from API level 14, this method can be called when preview is |
| 1688 | * active. |
| 1689 | * |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1690 | * <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in |
| 1691 | * API level 24, the default orientation will be such that applications in forced-landscape mode |
| 1692 | * will have correct preview orientation, which may be either a default of 0 or |
| 1693 | * 180. Applications that operate in portrait mode or allow for changing orientation must still |
| 1694 | * call this method after each orientation change to ensure correct preview display in all |
| 1695 | * cases.</p> |
| 1696 | * |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1697 | * @param degrees the angle that the picture will be rotated clockwise. |
Eino-Ville Talvala | 6c91e2c | 2016-03-25 11:54:39 -0700 | [diff] [blame] | 1698 | * Valid values are 0, 90, 180, and 270. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1699 | * @throws RuntimeException if setting orientation fails; usually this would |
| 1700 | * be because of a hardware or other low-level error, or because |
| 1701 | * release() has been called on this Camera instance. |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 1702 | * @see #setPreviewDisplay(SurfaceHolder) |
Chih-Chung Chang | d1d7706 | 2010-01-22 17:49:48 -0800 | [diff] [blame] | 1703 | */ |
| 1704 | public native final void setDisplayOrientation(int degrees); |
| 1705 | |
| 1706 | /** |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1707 | * <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] | 1708 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1709 | * <p>By default, the camera plays the system-defined camera shutter sound |
| 1710 | * when {@link #takePicture} is called. Using this method, the shutter sound |
| 1711 | * can be disabled. It is strongly recommended that an alternative shutter |
| 1712 | * sound is played in the {@link ShutterCallback} when the system shutter |
| 1713 | * sound is disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1714 | * |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1715 | * <p>Note that devices may not always allow disabling the camera shutter |
| 1716 | * sound. If the shutter sound state cannot be set to the desired value, |
| 1717 | * this method will return false. {@link CameraInfo#canDisableShutterSound} |
| 1718 | * can be used to determine whether the device will allow the shutter sound |
| 1719 | * to be disabled.</p> |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1720 | * |
| 1721 | * @param enabled whether the camera should play the system shutter sound |
| 1722 | * when {@link #takePicture takePicture} is called. |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1723 | * @return {@code true} if the shutter sound state was successfully |
| 1724 | * changed. {@code false} if the shutter sound state could not be |
| 1725 | * changed. {@code true} is also returned if shutter sound playback |
| 1726 | * is already set to the requested state. |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 1727 | * @throws RuntimeException if the call fails; usually this would be because |
| 1728 | * of a hardware or other low-level error, or because release() has been |
| 1729 | * called on this Camera instance. |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1730 | * @see #takePicture |
Eino-Ville Talvala | 487acdf | 2012-09-24 11:30:24 -0700 | [diff] [blame] | 1731 | * @see CameraInfo#canDisableShutterSound |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1732 | * @see ShutterCallback |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1733 | */ |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1734 | public final boolean enableShutterSound(boolean enabled) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1735 | boolean canDisableShutterSound = true; |
| 1736 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 1737 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 1738 | try { |
| 1739 | if (audioService.isCameraSoundForced()) { |
| 1740 | canDisableShutterSound = false; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1741 | } |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1742 | } catch (RemoteException e) { |
| 1743 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 1744 | } |
| 1745 | if (!enabled && !canDisableShutterSound) { |
| 1746 | return false; |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1747 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1748 | synchronized (mShutterSoundLock) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1749 | mShutterSoundEnabledFromApp = enabled; |
| 1750 | // Return the result of _enableShutterSound(enabled) in all cases. |
| 1751 | // 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] | 1752 | boolean ret = _enableShutterSound(enabled); |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1753 | if (enabled && !mHasAppOpsPlayAudio) { |
| 1754 | Log.i(TAG, "Shutter sound is not allowed by AppOpsManager"); |
| 1755 | if (canDisableShutterSound) { |
| 1756 | _enableShutterSound(false); |
| 1757 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1758 | } |
| 1759 | return ret; |
| 1760 | } |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Igor Murashkin | 6653362 | 2014-08-19 14:51:47 -0700 | [diff] [blame] | 1763 | /** |
| 1764 | * Disable the shutter sound unconditionally. |
| 1765 | * |
| 1766 | * <p> |
| 1767 | * This is only guaranteed to work for legacy cameras |
| 1768 | * (i.e. initialized with {@link #cameraInitUnspecified}). Trying to call this on |
| 1769 | * a regular camera will force a conditional check in the camera service. |
| 1770 | * </p> |
| 1771 | * |
| 1772 | * @return {@code true} if the shutter sound state was successfully |
| 1773 | * changed. {@code false} if the shutter sound state could not be |
| 1774 | * changed. {@code true} is also returned if shutter sound playback |
| 1775 | * is already set to the requested state. |
| 1776 | * |
| 1777 | * @hide |
| 1778 | */ |
| 1779 | public final boolean disableShutterSound() { |
| 1780 | return _enableShutterSound(/*enabled*/false); |
| 1781 | } |
| 1782 | |
Eino-Ville Talvala | 4f8e5ce | 2012-10-08 18:16:35 -0700 | [diff] [blame] | 1783 | private native final boolean _enableShutterSound(boolean enabled); |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1784 | |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1785 | private static class IAppOpsCallbackWrapper extends IAppOpsCallback.Stub { |
| 1786 | private final WeakReference<Camera> mWeakCamera; |
| 1787 | |
| 1788 | IAppOpsCallbackWrapper(Camera camera) { |
| 1789 | mWeakCamera = new WeakReference<Camera>(camera); |
| 1790 | } |
| 1791 | |
| 1792 | @Override |
| 1793 | public void opChanged(int op, int uid, String packageName) { |
| 1794 | if (op == AppOpsManager.OP_PLAY_AUDIO) { |
| 1795 | final Camera camera = mWeakCamera.get(); |
| 1796 | if (camera != null) { |
| 1797 | camera.updateAppOpsPlayAudio(); |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | private void updateAppOpsPlayAudio() { |
| 1804 | synchronized (mShutterSoundLock) { |
| 1805 | boolean oldHasAppOpsPlayAudio = mHasAppOpsPlayAudio; |
| 1806 | try { |
| 1807 | int mode = AppOpsManager.MODE_IGNORED; |
| 1808 | if (mAppOps != null) { |
| 1809 | mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO, |
| 1810 | AudioAttributes.USAGE_ASSISTANCE_SONIFICATION, |
| 1811 | Process.myUid(), ActivityThread.currentPackageName()); |
| 1812 | } |
| 1813 | mHasAppOpsPlayAudio = mode == AppOpsManager.MODE_ALLOWED; |
| 1814 | } catch (RemoteException e) { |
| 1815 | Log.e(TAG, "AppOpsService check audio operation failed"); |
| 1816 | mHasAppOpsPlayAudio = false; |
| 1817 | } |
| 1818 | if (oldHasAppOpsPlayAudio != mHasAppOpsPlayAudio) { |
| 1819 | if (!mHasAppOpsPlayAudio) { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1820 | IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); |
| 1821 | IAudioService audioService = IAudioService.Stub.asInterface(b); |
| 1822 | try { |
| 1823 | if (audioService.isCameraSoundForced()) { |
| 1824 | return; |
| 1825 | } |
| 1826 | } catch (RemoteException e) { |
| 1827 | Log.e(TAG, "Audio service is unavailable for queries"); |
| 1828 | } |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1829 | _enableShutterSound(false); |
| 1830 | } else { |
jiabin | e059e45 | 2018-05-07 15:16:44 -0700 | [diff] [blame] | 1831 | enableShutterSound(mShutterSoundEnabledFromApp); |
jiabin | 503e1fd | 2018-04-19 16:39:44 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
Eino-Ville Talvala | 69fe527 | 2012-09-07 12:26:40 -0700 | [diff] [blame] | 1837 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1838 | * Callback interface for zoom changes during a smooth zoom operation. |
| 1839 | * |
| 1840 | * @see #setZoomChangeListener(OnZoomChangeListener) |
| 1841 | * @see #startSmoothZoom(int) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1842 | * |
| 1843 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1844 | * applications. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1845 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1846 | @Deprecated |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1847 | public interface OnZoomChangeListener |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1848 | { |
| 1849 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 1850 | * Called when the zoom value has changed during a smooth zoom. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1851 | * |
| 1852 | * @param zoomValue the current zoom value. In smooth zoom mode, camera |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1853 | * calls this for every new zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 1854 | * @param stopped whether smooth zoom is stopped. If the value is true, |
| 1855 | * this is the last zoom update for the application. |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1856 | * @param camera the Camera service object |
| 1857 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1858 | void onZoomChange(int zoomValue, boolean stopped, Camera camera); |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1859 | }; |
| 1860 | |
| 1861 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1862 | * 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] | 1863 | * camera driver during smooth zoom. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1864 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1865 | * @param listener the listener to notify |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 1866 | * @see #startSmoothZoom(int) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1867 | */ |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1868 | public final void setZoomChangeListener(OnZoomChangeListener listener) |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1869 | { |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 1870 | mZoomListener = listener; |
Dave Sparks | e8b26e1 | 2009-07-14 10:35:40 -0700 | [diff] [blame] | 1871 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 1872 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1873 | /** |
| 1874 | * Callback interface for face detected in the preview frame. |
| 1875 | * |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1876 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1877 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1878 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1879 | @Deprecated |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1880 | public interface FaceDetectionListener |
| 1881 | { |
| 1882 | /** |
| 1883 | * Notify the listener of the detected faces in the preview frame. |
| 1884 | * |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1885 | * @param faces The detected faces in a list |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1886 | * @param camera The {@link Camera} service object |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1887 | */ |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1888 | void onFaceDetection(Face[] faces, Camera camera); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1892 | * 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] | 1893 | * preview frame. |
| 1894 | * |
| 1895 | * @param listener the listener to notify |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1896 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1897 | */ |
| 1898 | public final void setFaceDetectionListener(FaceDetectionListener listener) |
| 1899 | { |
| 1900 | mFaceListener = listener; |
| 1901 | } |
| 1902 | |
| 1903 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1904 | * 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] | 1905 | * The camera will notify {@link FaceDetectionListener} of the detected |
| 1906 | * faces in the preview frame. The detected faces may be the same as the |
| 1907 | * previous ones. Applications should call {@link #stopFaceDetection} to |
| 1908 | * stop the face detection. This method is supported if {@link |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1909 | * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1910 | * If the face detection has started, apps should not call this again. |
| 1911 | * |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1912 | * <p>When the face detection is running, {@link Parameters#setWhiteBalance(String)}, |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1913 | * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} |
Wu-cheng Li | 8c13670 | 2011-08-12 20:25:00 +0800 | [diff] [blame] | 1914 | * have no effect. The camera uses the detected faces to do auto-white balance, |
| 1915 | * auto exposure, and autofocus. |
| 1916 | * |
| 1917 | * <p>If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera |
| 1918 | * will stop sending face callbacks. The last face callback indicates the |
| 1919 | * areas used to do autofocus. After focus completes, face detection will |
| 1920 | * resume sending face callbacks. If the apps call {@link |
| 1921 | * #cancelAutoFocus()}, the face callbacks will also resume.</p> |
| 1922 | * |
| 1923 | * <p>After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 1924 | * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming |
| 1925 | * preview with {@link #startPreview()}, the apps should call this method |
| 1926 | * again to resume face detection.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1927 | * |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1928 | * @throws IllegalArgumentException if the face detection is unsupported. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1929 | * @throws RuntimeException if the method fails or the face detection is |
| 1930 | * already running. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1931 | * @see FaceDetectionListener |
| 1932 | * @see #stopFaceDetection() |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1933 | * @see Parameters#getMaxNumDetectedFaces() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1934 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1935 | public final void startFaceDetection() { |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1936 | if (mFaceDetectionRunning) { |
| 1937 | throw new RuntimeException("Face detection is already running"); |
| 1938 | } |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1939 | _startFaceDetection(CAMERA_FACE_DETECTION_HW); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1940 | mFaceDetectionRunning = true; |
| 1941 | } |
| 1942 | |
| 1943 | /** |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1944 | * Stops the face detection. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1945 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1946 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1947 | */ |
| 1948 | public final void stopFaceDetection() { |
| 1949 | _stopFaceDetection(); |
| 1950 | mFaceDetectionRunning = false; |
| 1951 | } |
| 1952 | |
| 1953 | private native final void _startFaceDetection(int type); |
| 1954 | private native final void _stopFaceDetection(); |
| 1955 | |
| 1956 | /** |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1957 | * Information about a face identified through camera face detection. |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 1958 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1959 | * <p>When face detection is used with a camera, the {@link FaceDetectionListener} returns a |
| 1960 | * list of face objects for use in focusing and metering.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1961 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 1962 | * @see FaceDetectionListener |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1963 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 1964 | * applications. |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1965 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 1966 | @Deprecated |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1967 | public static class Face { |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 1968 | /** |
| 1969 | * Create an empty face. |
| 1970 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 1971 | public Face() { |
| 1972 | } |
| 1973 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 1974 | /** |
| 1975 | * Bounds of the face. (-1000, -1000) represents the top-left of the |
| 1976 | * 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] | 1977 | * the field of view. For example, suppose the size of the viewfinder UI |
| 1978 | * 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] | 1979 | * The corresponding viewfinder rect should be (0, 0, 400, 240). It is |
| 1980 | * guaranteed left < right and top < bottom. The coordinates can be |
| 1981 | * smaller than -1000 or bigger than 1000. But at least one vertex will |
| 1982 | * be within (-1000, -1000) and (1000, 1000). |
Wu-cheng Li | f0d6a48 | 2011-07-28 05:30:59 +0800 | [diff] [blame] | 1983 | * |
| 1984 | * <p>The direction is relative to the sensor orientation, that is, what |
| 1985 | * 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] | 1986 | * mirroring of {@link #setDisplayOrientation(int)}. The face bounding |
| 1987 | * rectangle does not provide any information about face orientation.</p> |
| 1988 | * |
| 1989 | * <p>Here is the matrix to convert driver coordinates to View coordinates |
| 1990 | * in pixels.</p> |
| 1991 | * <pre> |
| 1992 | * Matrix matrix = new Matrix(); |
| 1993 | * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; |
| 1994 | * // Need mirror for front camera. |
| 1995 | * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); |
| 1996 | * matrix.setScale(mirror ? -1 : 1, 1); |
| 1997 | * // This is the value for android.hardware.Camera.setDisplayOrientation. |
| 1998 | * matrix.postRotate(displayOrientation); |
| 1999 | * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). |
| 2000 | * // UI coordinates range from (0, 0) to (width, height). |
| 2001 | * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f); |
| 2002 | * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f); |
| 2003 | * </pre> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2004 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 2005 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2006 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 2007 | public Rect rect; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2008 | |
| 2009 | /** |
Eino-Ville Talvala | 8df3b2b | 2012-09-15 14:30:12 -0700 | [diff] [blame] | 2010 | * <p>The confidence level for the detection of the face. The range is 1 to |
| 2011 | * 100. 100 is the highest confidence.</p> |
| 2012 | * |
| 2013 | * <p>Depending on the device, even very low-confidence faces may be |
| 2014 | * listed, so applications should filter out faces with low confidence, |
| 2015 | * depending on the use case. For a typical point-and-shoot camera |
| 2016 | * application that wishes to display rectangles around detected faces, |
| 2017 | * filtering out faces with confidence less than 50 is recommended.</p> |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2018 | * |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 2019 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2020 | */ |
Wu-cheng Li | bb1e275 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 2021 | public int score; |
Wei Hua | d52b308 | 2011-08-19 13:01:51 -0700 | [diff] [blame] | 2022 | |
| 2023 | /** |
| 2024 | * An unique id per face while the face is visible to the tracker. If |
| 2025 | * the face leaves the field-of-view and comes back, it will get a new |
| 2026 | * id. This is an optional field, may not be supported on all devices. |
| 2027 | * If not supported, id will always be set to -1. The optional fields |
| 2028 | * are supported as a set. Either they are all valid, or none of them |
| 2029 | * are. |
| 2030 | */ |
| 2031 | public int id = -1; |
| 2032 | |
| 2033 | /** |
| 2034 | * The coordinates of the center of the left eye. The coordinates are in |
| 2035 | * the same space as the ones for {@link #rect}. This is an optional |
| 2036 | * field, may not be supported on all devices. If not supported, the |
| 2037 | * value will always be set to null. The optional fields are supported |
| 2038 | * as a set. Either they are all valid, or none of them are. |
| 2039 | */ |
| 2040 | public Point leftEye = null; |
| 2041 | |
| 2042 | /** |
| 2043 | * The coordinates of the center of the right eye. The coordinates are |
| 2044 | * in the same space as the ones for {@link #rect}.This is an optional |
| 2045 | * field, may not be supported on all devices. If not supported, the |
| 2046 | * value will always be set to null. The optional fields are supported |
| 2047 | * as a set. Either they are all valid, or none of them are. |
| 2048 | */ |
| 2049 | public Point rightEye = null; |
| 2050 | |
| 2051 | /** |
| 2052 | * The coordinates of the center of the mouth. The coordinates are in |
| 2053 | * the same space as the ones for {@link #rect}. This is an optional |
| 2054 | * field, may not be supported on all devices. If not supported, the |
| 2055 | * value will always be set to null. The optional fields are supported |
| 2056 | * as a set. Either they are all valid, or none of them are. |
| 2057 | */ |
| 2058 | public Point mouth = null; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2059 | } |
| 2060 | |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2061 | /** |
| 2062 | * Unspecified camera error. |
| 2063 | * @see Camera.ErrorCallback |
| 2064 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | public static final int CAMERA_ERROR_UNKNOWN = 1; |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2066 | |
| 2067 | /** |
Ruben Brunk | e91b925 | 2015-04-14 13:38:06 -0700 | [diff] [blame] | 2068 | * Camera was disconnected due to use by higher priority user. |
| 2069 | * @see Camera.ErrorCallback |
| 2070 | */ |
| 2071 | public static final int CAMERA_ERROR_EVICTED = 2; |
| 2072 | |
| 2073 | /** |
Yin-Chia Yeh | a07cd32 | 2018-05-31 12:11:42 -0700 | [diff] [blame] | 2074 | * Camera was disconnected due to device policy change or client |
| 2075 | * application going to background. |
| 2076 | * @see Camera.ErrorCallback |
| 2077 | * |
| 2078 | * @hide |
| 2079 | */ |
| 2080 | public static final int CAMERA_ERROR_DISABLED = 3; |
| 2081 | |
| 2082 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2083 | * Media server died. In this case, the application must release the |
| 2084 | * Camera object and instantiate a new one. |
| 2085 | * @see Camera.ErrorCallback |
| 2086 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | public static final int CAMERA_ERROR_SERVER_DIED = 100; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2090 | * Callback interface for camera error notification. |
| 2091 | * |
| 2092 | * @see #setErrorCallback(ErrorCallback) |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2093 | * |
| 2094 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2095 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2097 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | public interface ErrorCallback |
| 2099 | { |
| 2100 | /** |
| 2101 | * Callback for camera errors. |
| 2102 | * @param error error code: |
| 2103 | * <ul> |
| 2104 | * <li>{@link #CAMERA_ERROR_UNKNOWN} |
| 2105 | * <li>{@link #CAMERA_ERROR_SERVER_DIED} |
| 2106 | * </ul> |
| 2107 | * @param camera the Camera service object |
| 2108 | */ |
| 2109 | void onError(int error, Camera camera); |
| 2110 | }; |
| 2111 | |
| 2112 | /** |
| 2113 | * Registers a callback to be invoked when an error occurs. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2114 | * @param cb The callback to run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | */ |
| 2116 | public final void setErrorCallback(ErrorCallback cb) |
| 2117 | { |
| 2118 | mErrorCallback = cb; |
| 2119 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2120 | |
Yin-Chia Yeh | a07cd32 | 2018-05-31 12:11:42 -0700 | [diff] [blame] | 2121 | /** |
| 2122 | * Registers a callback to be invoked when an error occurs. |
| 2123 | * The detailed error callback may contain error code that |
| 2124 | * gives more detailed information about the error. |
| 2125 | * |
| 2126 | * When a detailed callback is set, the callback set via |
| 2127 | * #setErrorCallback(ErrorCallback) will stop receiving |
| 2128 | * onError call. |
| 2129 | * |
| 2130 | * @param cb The callback to run |
| 2131 | * |
| 2132 | * @hide |
| 2133 | */ |
| 2134 | public final void setDetailedErrorCallback(ErrorCallback cb) |
| 2135 | { |
| 2136 | mDetailedErrorCallback = cb; |
| 2137 | } |
| 2138 | |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 2139 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | private native final void native_setParameters(String params); |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 2141 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | private native final String native_getParameters(); |
| 2143 | |
| 2144 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2145 | * Changes the settings for this Camera service. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2146 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | * @param params the Parameters to use for this Camera service |
Wu-cheng Li | 99a3f3e | 2010-11-19 15:56:16 +0800 | [diff] [blame] | 2148 | * @throws RuntimeException if any parameter is invalid or not supported. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2149 | * @see #getParameters() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | */ |
| 2151 | public void setParameters(Parameters params) { |
Eino-Ville Talvala | 7005b67 | 2013-04-02 15:46:38 -0700 | [diff] [blame] | 2152 | // If using preview allocations, don't allow preview size changes |
| 2153 | if (mUsingPreviewAllocation) { |
| 2154 | Size newPreviewSize = params.getPreviewSize(); |
| 2155 | Size currentPreviewSize = getParameters().getPreviewSize(); |
| 2156 | if (newPreviewSize.width != currentPreviewSize.width || |
| 2157 | newPreviewSize.height != currentPreviewSize.height) { |
| 2158 | throw new IllegalStateException("Cannot change preview size" + |
| 2159 | " while a preview allocation is configured."); |
| 2160 | } |
| 2161 | } |
| 2162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | native_setParameters(params.flatten()); |
| 2164 | } |
| 2165 | |
| 2166 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2167 | * Returns the current settings for this Camera service. |
| 2168 | * If modifications are made to the returned Parameters, they must be passed |
| 2169 | * to {@link #setParameters(Camera.Parameters)} to take effect. |
| 2170 | * |
Eino-Ville Talvala | 06a7718 | 2017-09-15 12:43:24 -0700 | [diff] [blame] | 2171 | * @throws RuntimeException if reading parameters fails; usually this would |
| 2172 | * be because of a hardware or other low-level error, or because |
| 2173 | * release() has been called on this Camera instance. |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2174 | * @see #setParameters(Camera.Parameters) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | */ |
| 2176 | public Parameters getParameters() { |
| 2177 | Parameters p = new Parameters(); |
| 2178 | String s = native_getParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | p.unflatten(s); |
| 2180 | return p; |
| 2181 | } |
| 2182 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2183 | /** @hide |
| 2184 | * Returns the current cct value of white balance. |
| 2185 | * |
| 2186 | * If it's in AWB mode, cct is determined by stats/awb module. |
| 2187 | * |
| 2188 | * If it's in Manual WB mode, it actually returns cct value |
| 2189 | * set by user via {@link #setParameters(Camera.Parameters)}. |
| 2190 | */ |
| 2191 | public int getWBCurrentCCT() { |
| 2192 | Parameters p = new Parameters(); |
| 2193 | String s = native_getParameters(); |
| 2194 | p.unflatten(s); |
| 2195 | |
| 2196 | int cct = 0; |
| 2197 | if (p.getWBCurrentCCT() != null) { |
| 2198 | cct = Integer.parseInt(p.getWBCurrentCCT()); |
| 2199 | } |
| 2200 | |
| 2201 | return cct; |
| 2202 | } |
| 2203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | /** |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2205 | * Returns an empty {@link Parameters} for testing purpose. |
| 2206 | * |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 2207 | * @return a Parameter object. |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2208 | * |
| 2209 | * @hide |
| 2210 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 2211 | @UnsupportedAppUsage |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2212 | public static Parameters getEmptyParameters() { |
| 2213 | Camera camera = new Camera(); |
| 2214 | return camera.new Parameters(); |
| 2215 | } |
| 2216 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2217 | /* ### QC ADD-ONS: START */ |
| 2218 | private static int byteToInt(byte[] b, int offset) { |
| 2219 | int value = 0; |
| 2220 | for (int i = 0; i < 4; i++) { |
| 2221 | int shift = (4 - 1 - i) * 8; |
| 2222 | value += (b[(3-i) + offset] & 0x000000FF) << shift; |
| 2223 | } |
| 2224 | return value; |
| 2225 | } |
| 2226 | /** @hide |
| 2227 | * Handles the callback for when Camera Data is available. |
| 2228 | * data is read from the camera. |
| 2229 | */ |
| 2230 | public interface CameraDataCallback { |
| 2231 | /** |
| 2232 | * Callback for when camera data is available. |
| 2233 | * |
| 2234 | * @param data a int array of the camera data |
| 2235 | * @param camera the Camera service object |
| 2236 | */ |
| 2237 | void onCameraData(int[] data, Camera camera); |
| 2238 | }; |
| 2239 | |
| 2240 | /** @hide |
| 2241 | * Set camera histogram mode and registers a callback function to run. |
| 2242 | * Only valid after startPreview() has been called. |
| 2243 | * |
| 2244 | * @param cb the callback to run |
| 2245 | */ |
| 2246 | public final void setHistogramMode(CameraDataCallback cb) |
| 2247 | { |
| 2248 | mCameraDataCallback = cb; |
| 2249 | native_setHistogramMode(cb!=null); |
| 2250 | } |
| 2251 | private native final void native_setHistogramMode(boolean mode); |
| 2252 | |
| 2253 | /** @hide |
| 2254 | * Set camera histogram command to send data. |
| 2255 | * |
| 2256 | */ |
| 2257 | public final void sendHistogramData() |
| 2258 | { |
| 2259 | native_sendHistogramData(); |
| 2260 | } |
| 2261 | private native final void native_sendHistogramData(); |
| 2262 | |
| 2263 | /** @hide |
| 2264 | * Handles the callback for when Camera Meta Data is available. |
| 2265 | * Meta data is read from the camera. |
| 2266 | */ |
| 2267 | public interface CameraMetaDataCallback { |
| 2268 | /** |
| 2269 | * Callback for when camera meta data is available. |
| 2270 | * |
| 2271 | * @param data a byte array of the camera meta data |
| 2272 | * @param camera the Camera service object |
| 2273 | */ |
| 2274 | void onCameraMetaData(byte[] data, Camera camera); |
| 2275 | }; |
| 2276 | |
| 2277 | /** @hide |
| 2278 | * Set camera meta data and registers a callback function to run. |
| 2279 | * Only valid after startPreview() has been called. |
| 2280 | * |
| 2281 | * @param cb the callback to run |
| 2282 | */ |
| 2283 | public final void setMetadataCb(CameraMetaDataCallback cb) |
| 2284 | { |
| 2285 | mCameraMetaDataCallback = cb; |
| 2286 | native_setMetadataCb(cb!=null); |
| 2287 | } |
| 2288 | private native final void native_setMetadataCb(boolean mode); |
| 2289 | |
| 2290 | /** @hide |
| 2291 | * Set camera face detection command to send meta data. |
| 2292 | */ |
| 2293 | public final void sendMetaData() |
| 2294 | { |
| 2295 | native_sendMetaData(); |
| 2296 | } |
| 2297 | private native final void native_sendMetaData(); |
| 2298 | |
| 2299 | /** @hide |
| 2300 | * Configure longshot mode. Available only in ZSL. |
| 2301 | * |
| 2302 | * @param enable enable/disable this mode |
| 2303 | */ |
| 2304 | public final void setLongshot(boolean enable) |
| 2305 | { |
| 2306 | native_setLongshot(enable); |
| 2307 | } |
| 2308 | private native final void native_setLongshot(boolean enable); |
| 2309 | |
| 2310 | /** @hide |
| 2311 | * Handles the Touch Co-ordinate. |
| 2312 | */ |
| 2313 | public class Coordinate { |
| 2314 | /** |
| 2315 | * Sets the x,y co-ordinates for a touch event |
| 2316 | * |
| 2317 | * @param x the x co-ordinate (pixels) |
| 2318 | * @param y the y co-ordinate (pixels) |
| 2319 | */ |
| 2320 | public Coordinate(int x, int y) { |
| 2321 | xCoordinate = x; |
| 2322 | yCoordinate = y; |
| 2323 | } |
| 2324 | /** |
| 2325 | * Compares {@code obj} to this co-ordinate. |
| 2326 | * |
| 2327 | * @param obj the object to compare this co-ordinate with. |
| 2328 | * @return {@code true} if the xCoordinate and yCoordinate of {@code obj} is the |
| 2329 | * same as those of this coordinate. {@code false} otherwise. |
| 2330 | */ |
| 2331 | @Override |
| 2332 | public boolean equals(Object obj) { |
| 2333 | if (!(obj instanceof Coordinate)) { |
| 2334 | return false; |
| 2335 | } |
| 2336 | Coordinate c = (Coordinate) obj; |
| 2337 | return xCoordinate == c.xCoordinate && yCoordinate == c.yCoordinate; |
| 2338 | } |
| 2339 | |
| 2340 | /** x co-ordinate for the touch event*/ |
| 2341 | public int xCoordinate; |
| 2342 | |
| 2343 | /** y co-ordinate for the touch event */ |
| 2344 | public int yCoordinate; |
| 2345 | }; |
| 2346 | |
| 2347 | /** @hide |
| 2348 | * Returns the current focus position. |
| 2349 | * |
| 2350 | * If it's in AF mode, it's the lens position after af is done. |
| 2351 | * |
| 2352 | * If it's in Manual Focus mode, it actually returns the value |
| 2353 | * set by user via {@link #setParameters(Camera.Parameters)}. |
| 2354 | */ |
| 2355 | public int getCurrentFocusPosition() { |
| 2356 | Parameters p = new Parameters(); |
| 2357 | String s = native_getParameters(); |
| 2358 | p.unflatten(s); |
| 2359 | |
| 2360 | int focus_pos = -1; |
| 2361 | if (p.getCurrentFocusPosition() != null) { |
| 2362 | focus_pos = Integer.parseInt(p.getCurrentFocusPosition()); |
| 2363 | } |
| 2364 | return focus_pos; |
| 2365 | } |
| 2366 | |
| 2367 | /* ### QC ADD-ONS: END */ |
Wu-cheng Li | 1c04a33 | 2011-11-22 18:21:18 +0800 | [diff] [blame] | 2368 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2369 | * Returns a copied {@link Parameters}; for shim use only. |
| 2370 | * |
| 2371 | * @param parameters a non-{@code null} parameters |
| 2372 | * @return a Parameter object, with all the parameters copied from {@code parameters}. |
| 2373 | * |
| 2374 | * @throws NullPointerException if {@code parameters} was {@code null} |
| 2375 | * @hide |
| 2376 | */ |
| 2377 | public static Parameters getParametersCopy(Camera.Parameters parameters) { |
| 2378 | if (parameters == null) { |
| 2379 | throw new NullPointerException("parameters must not be null"); |
| 2380 | } |
| 2381 | |
| 2382 | Camera camera = parameters.getOuter(); |
| 2383 | Parameters p = camera.new Parameters(); |
| 2384 | p.copyFrom(parameters); |
| 2385 | |
| 2386 | return p; |
| 2387 | } |
| 2388 | |
| 2389 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2390 | * Image size (width and height dimensions). |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2391 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2392 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2394 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | public class Size { |
| 2396 | /** |
| 2397 | * Sets the dimensions for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2398 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | * @param w the photo width (pixels) |
| 2400 | * @param h the photo height (pixels) |
| 2401 | */ |
| 2402 | public Size(int w, int h) { |
| 2403 | width = w; |
| 2404 | height = h; |
| 2405 | } |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2406 | /** |
| 2407 | * Compares {@code obj} to this size. |
| 2408 | * |
| 2409 | * @param obj the object to compare this size with. |
| 2410 | * @return {@code true} if the width and height of {@code obj} is the |
| 2411 | * same as those of this size. {@code false} otherwise. |
| 2412 | */ |
| 2413 | @Override |
| 2414 | public boolean equals(Object obj) { |
| 2415 | if (!(obj instanceof Size)) { |
| 2416 | return false; |
| 2417 | } |
| 2418 | Size s = (Size) obj; |
| 2419 | return width == s.width && height == s.height; |
| 2420 | } |
| 2421 | @Override |
| 2422 | public int hashCode() { |
| 2423 | return width * 32713 + height; |
| 2424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | /** width of the picture */ |
| 2426 | public int width; |
| 2427 | /** height of the picture */ |
| 2428 | public int height; |
| 2429 | }; |
| 2430 | |
| 2431 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2432 | * <p>The Area class is used for choosing specific metering and focus areas for |
| 2433 | * the camera to use when calculating auto-exposure, auto-white balance, and |
| 2434 | * auto-focus.</p> |
| 2435 | * |
| 2436 | * <p>To find out how many simultaneous areas a given camera supports, use |
| 2437 | * {@link Parameters#getMaxNumMeteringAreas()} and |
| 2438 | * {@link Parameters#getMaxNumFocusAreas()}. If metering or focusing area |
| 2439 | * selection is unsupported, these methods will return 0.</p> |
| 2440 | * |
| 2441 | * <p>Each Area consists of a rectangle specifying its bounds, and a weight |
| 2442 | * that determines its importance. The bounds are relative to the camera's |
| 2443 | * current field of view. The coordinates are mapped so that (-1000, -1000) |
| 2444 | * is always the top-left corner of the current field of view, and (1000, |
| 2445 | * 1000) is always the bottom-right corner of the current field of |
| 2446 | * view. Setting Areas with bounds outside that range is not allowed. Areas |
| 2447 | * with zero or negative width or height are not allowed.</p> |
| 2448 | * |
| 2449 | * <p>The weight must range from 1 to 1000, and represents a weight for |
| 2450 | * every pixel in the area. This means that a large metering area with |
| 2451 | * the same weight as a smaller area will have more effect in the |
| 2452 | * metering result. Metering areas can overlap and the driver |
| 2453 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2454 | * |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2455 | * @see Parameters#setFocusAreas(List) |
| 2456 | * @see Parameters#getFocusAreas() |
| 2457 | * @see Parameters#getMaxNumFocusAreas() |
| 2458 | * @see Parameters#setMeteringAreas(List) |
| 2459 | * @see Parameters#getMeteringAreas() |
| 2460 | * @see Parameters#getMaxNumMeteringAreas() |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2461 | * |
| 2462 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2463 | * applications. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2464 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2465 | @Deprecated |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2466 | public static class Area { |
| 2467 | /** |
| 2468 | * Create an area with specified rectangle and weight. |
| 2469 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2470 | * @param rect the bounds of the area. |
| 2471 | * @param weight the weight of the area. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2472 | */ |
| 2473 | public Area(Rect rect, int weight) { |
| 2474 | this.rect = rect; |
| 2475 | this.weight = weight; |
| 2476 | } |
| 2477 | /** |
| 2478 | * Compares {@code obj} to this area. |
| 2479 | * |
| 2480 | * @param obj the object to compare this area with. |
| 2481 | * @return {@code true} if the rectangle and weight of {@code obj} is |
| 2482 | * the same as those of this area. {@code false} otherwise. |
| 2483 | */ |
| 2484 | @Override |
| 2485 | public boolean equals(Object obj) { |
| 2486 | if (!(obj instanceof Area)) { |
| 2487 | return false; |
| 2488 | } |
| 2489 | Area a = (Area) obj; |
| 2490 | if (rect == null) { |
| 2491 | if (a.rect != null) return false; |
| 2492 | } else { |
| 2493 | if (!rect.equals(a.rect)) return false; |
| 2494 | } |
| 2495 | return weight == a.weight; |
| 2496 | } |
| 2497 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2498 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2499 | * Bounds of the area. (-1000, -1000) represents the top-left of the |
| 2500 | * camera field of view, and (1000, 1000) represents the bottom-right of |
| 2501 | * the field of view. Setting bounds outside that range is not |
| 2502 | * allowed. Bounds with zero or negative width or height are not |
| 2503 | * allowed. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2504 | * |
| 2505 | * @see Parameters#getFocusAreas() |
| 2506 | * @see Parameters#getMeteringAreas() |
| 2507 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2508 | public Rect rect; |
| 2509 | |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2510 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 2511 | * Weight of the area. The weight must range from 1 to 1000, and |
| 2512 | * represents a weight for every pixel in the area. This means that a |
| 2513 | * large metering area with the same weight as a smaller area will have |
| 2514 | * more effect in the metering result. Metering areas can overlap and |
| 2515 | * the driver will add the weights in the overlap region. |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2516 | * |
| 2517 | * @see Parameters#getFocusAreas() |
| 2518 | * @see Parameters#getMeteringAreas() |
| 2519 | */ |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2520 | public int weight; |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 2521 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2522 | |
| 2523 | /** |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2524 | * Camera service settings. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2525 | * |
| 2526 | * <p>To make camera parameters take effect, applications have to call |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2527 | * {@link Camera#setParameters(Camera.Parameters)}. For example, after |
| 2528 | * {@link Camera.Parameters#setWhiteBalance} is called, white balance is not |
| 2529 | * actually changed until {@link Camera#setParameters(Camera.Parameters)} |
| 2530 | * is called with the changed parameters object. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2531 | * |
| 2532 | * <p>Different devices may have different camera capabilities, such as |
| 2533 | * picture size or flash modes. The application should query the camera |
| 2534 | * capabilities before setting parameters. For example, the application |
Dan Egnor | bfcbeff | 2010-07-12 15:12:54 -0700 | [diff] [blame] | 2535 | * should call {@link Camera.Parameters#getSupportedColorEffects()} before |
| 2536 | * calling {@link Camera.Parameters#setColorEffect(String)}. If the |
| 2537 | * camera does not support color effects, |
| 2538 | * {@link Camera.Parameters#getSupportedColorEffects()} will return null. |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2539 | * |
| 2540 | * @deprecated We recommend using the new {@link android.hardware.camera2} API for new |
| 2541 | * applications. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | */ |
Eino-Ville Talvala | b942b05 | 2014-07-10 17:45:03 -0700 | [diff] [blame] | 2543 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | public class Parameters { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2545 | // Parameter keys to communicate with the camera driver. |
| 2546 | private static final String KEY_PREVIEW_SIZE = "preview-size"; |
| 2547 | private static final String KEY_PREVIEW_FORMAT = "preview-format"; |
| 2548 | private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2549 | private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2550 | private static final String KEY_PICTURE_SIZE = "picture-size"; |
| 2551 | private static final String KEY_PICTURE_FORMAT = "picture-format"; |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 2552 | private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2553 | private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; |
| 2554 | private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; |
| 2555 | private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; |
| 2556 | private static final String KEY_JPEG_QUALITY = "jpeg-quality"; |
| 2557 | private static final String KEY_ROTATION = "rotation"; |
| 2558 | private static final String KEY_GPS_LATITUDE = "gps-latitude"; |
| 2559 | private static final String KEY_GPS_LONGITUDE = "gps-longitude"; |
| 2560 | private static final String KEY_GPS_ALTITUDE = "gps-altitude"; |
| 2561 | private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 2562 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2563 | private static final String KEY_WHITE_BALANCE = "whitebalance"; |
| 2564 | private static final String KEY_EFFECT = "effect"; |
| 2565 | private static final String KEY_ANTIBANDING = "antibanding"; |
| 2566 | private static final String KEY_SCENE_MODE = "scene-mode"; |
| 2567 | private static final String KEY_FLASH_MODE = "flash-mode"; |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2568 | private static final String KEY_FOCUS_MODE = "focus-mode"; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 2569 | private static final String KEY_FOCUS_AREAS = "focus-areas"; |
| 2570 | 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] | 2571 | private static final String KEY_FOCAL_LENGTH = "focal-length"; |
| 2572 | private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; |
| 2573 | private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 2574 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 2575 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; |
| 2576 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; |
| 2577 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2578 | private static final String KEY_AUTO_EXPOSURE_LOCK = "auto-exposure-lock"; |
| 2579 | 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] | 2580 | private static final String KEY_AUTO_WHITEBALANCE_LOCK = "auto-whitebalance-lock"; |
| 2581 | 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] | 2582 | private static final String KEY_METERING_AREAS = "metering-areas"; |
| 2583 | 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] | 2584 | private static final String KEY_ZOOM = "zoom"; |
| 2585 | private static final String KEY_MAX_ZOOM = "max-zoom"; |
| 2586 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; |
| 2587 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; |
| 2588 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2589 | private static final String KEY_FOCUS_DISTANCES = "focus-distances"; |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 2590 | private static final String KEY_VIDEO_SIZE = "video-size"; |
| 2591 | private static final String KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO = |
| 2592 | "preferred-preview-size-for-video"; |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 2593 | private static final String KEY_MAX_NUM_DETECTED_FACES_HW = "max-num-detected-faces-hw"; |
| 2594 | 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] | 2595 | private static final String KEY_RECORDING_HINT = "recording-hint"; |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 2596 | private static final String KEY_VIDEO_SNAPSHOT_SUPPORTED = "video-snapshot-supported"; |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 2597 | private static final String KEY_VIDEO_STABILIZATION = "video-stabilization"; |
| 2598 | private static final String KEY_VIDEO_STABILIZATION_SUPPORTED = "video-stabilization-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2599 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2600 | // Parameter key suffix for supported values. |
| 2601 | private static final String SUPPORTED_VALUES_SUFFIX = "-values"; |
| 2602 | |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2603 | private static final String TRUE = "true"; |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 2604 | private static final String FALSE = "false"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 2605 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2606 | // Values for white balance settings. |
| 2607 | public static final String WHITE_BALANCE_AUTO = "auto"; |
| 2608 | public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; |
| 2609 | public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; |
| 2610 | public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; |
| 2611 | public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; |
| 2612 | public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; |
| 2613 | public static final String WHITE_BALANCE_TWILIGHT = "twilight"; |
| 2614 | public static final String WHITE_BALANCE_SHADE = "shade"; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2615 | /** @hide |
| 2616 | * wb manual cct mode. |
| 2617 | */ |
| 2618 | public static final String WHITE_BALANCE_MANUAL_CCT = "manual-cct"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2619 | |
| 2620 | // Values for color effect settings. |
| 2621 | public static final String EFFECT_NONE = "none"; |
| 2622 | public static final String EFFECT_MONO = "mono"; |
| 2623 | public static final String EFFECT_NEGATIVE = "negative"; |
| 2624 | public static final String EFFECT_SOLARIZE = "solarize"; |
| 2625 | public static final String EFFECT_SEPIA = "sepia"; |
| 2626 | public static final String EFFECT_POSTERIZE = "posterize"; |
| 2627 | public static final String EFFECT_WHITEBOARD = "whiteboard"; |
| 2628 | public static final String EFFECT_BLACKBOARD = "blackboard"; |
| 2629 | public static final String EFFECT_AQUA = "aqua"; |
| 2630 | |
| 2631 | // Values for antibanding settings. |
| 2632 | public static final String ANTIBANDING_AUTO = "auto"; |
| 2633 | public static final String ANTIBANDING_50HZ = "50hz"; |
| 2634 | public static final String ANTIBANDING_60HZ = "60hz"; |
| 2635 | public static final String ANTIBANDING_OFF = "off"; |
| 2636 | |
| 2637 | // Values for flash mode settings. |
| 2638 | /** |
| 2639 | * Flash will not be fired. |
| 2640 | */ |
| 2641 | public static final String FLASH_MODE_OFF = "off"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2642 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2643 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2644 | * Flash will be fired automatically when required. The flash may be fired |
| 2645 | * during preview, auto-focus, or snapshot depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2646 | */ |
| 2647 | public static final String FLASH_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2648 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2649 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2650 | * Flash will always be fired during snapshot. The flash may also be |
| 2651 | * fired during preview or auto-focus depending on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2652 | */ |
| 2653 | public static final String FLASH_MODE_ON = "on"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2654 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2655 | /** |
| 2656 | * Flash will be fired in red-eye reduction mode. |
| 2657 | */ |
| 2658 | public static final String FLASH_MODE_RED_EYE = "red-eye"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2659 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2660 | /** |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2661 | * Constant emission of light during preview, auto-focus and snapshot. |
| 2662 | * This can also be used for video recording. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2663 | */ |
Wu-cheng Li | 068ef42 | 2009-09-27 13:19:36 -0700 | [diff] [blame] | 2664 | public static final String FLASH_MODE_TORCH = "torch"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2665 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2666 | /** @hide |
| 2667 | * Scene mode is off. |
| 2668 | */ |
| 2669 | public static final String SCENE_MODE_ASD = "asd"; |
| 2670 | |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2671 | /** |
| 2672 | * Scene mode is off. |
| 2673 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2674 | public static final String SCENE_MODE_AUTO = "auto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2675 | |
| 2676 | /** |
| 2677 | * Take photos of fast moving objects. Same as {@link |
| 2678 | * #SCENE_MODE_SPORTS}. |
| 2679 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2680 | public static final String SCENE_MODE_ACTION = "action"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2681 | |
| 2682 | /** |
| 2683 | * Take people pictures. |
| 2684 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2685 | public static final String SCENE_MODE_PORTRAIT = "portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2686 | |
| 2687 | /** |
| 2688 | * Take pictures on distant objects. |
| 2689 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2690 | public static final String SCENE_MODE_LANDSCAPE = "landscape"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2691 | |
| 2692 | /** |
| 2693 | * Take photos at night. |
| 2694 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2695 | public static final String SCENE_MODE_NIGHT = "night"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2696 | |
| 2697 | /** |
| 2698 | * Take people pictures at night. |
| 2699 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2700 | public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2701 | |
| 2702 | /** |
| 2703 | * Take photos in a theater. Flash light is off. |
| 2704 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2705 | public static final String SCENE_MODE_THEATRE = "theatre"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2706 | |
| 2707 | /** |
| 2708 | * Take pictures on the beach. |
| 2709 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2710 | public static final String SCENE_MODE_BEACH = "beach"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2711 | |
| 2712 | /** |
| 2713 | * Take pictures on the snow. |
| 2714 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2715 | public static final String SCENE_MODE_SNOW = "snow"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2716 | |
| 2717 | /** |
| 2718 | * Take sunset photos. |
| 2719 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2720 | public static final String SCENE_MODE_SUNSET = "sunset"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2721 | |
| 2722 | /** |
| 2723 | * Avoid blurry pictures (for example, due to hand shake). |
| 2724 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2725 | public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2726 | |
| 2727 | /** |
| 2728 | * For shooting firework displays. |
| 2729 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2730 | public static final String SCENE_MODE_FIREWORKS = "fireworks"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2731 | |
| 2732 | /** |
| 2733 | * Take photos of fast moving objects. Same as {@link |
| 2734 | * #SCENE_MODE_ACTION}. |
| 2735 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2736 | public static final String SCENE_MODE_SPORTS = "sports"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2737 | |
| 2738 | /** |
| 2739 | * Take indoor low-light shot. |
| 2740 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2741 | public static final String SCENE_MODE_PARTY = "party"; |
Wu-cheng Li | 00e21f8 | 2010-05-28 16:43:38 +0800 | [diff] [blame] | 2742 | |
| 2743 | /** |
| 2744 | * Capture the naturally warm color of scenes lit by candles. |
| 2745 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2746 | public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2747 | /** @hide |
| 2748 | * SCENE_MODE_BACKLIGHT |
| 2749 | **/ |
| 2750 | public static final String SCENE_MODE_BACKLIGHT = "backlight"; |
| 2751 | /** @hide |
| 2752 | * SCENE_MODE_FLOWERS |
| 2753 | **/ |
| 2754 | public static final String SCENE_MODE_FLOWERS = "flowers"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2755 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2756 | /** |
| 2757 | * Applications are looking for a barcode. Camera driver will be |
| 2758 | * optimized for barcode reading. |
| 2759 | */ |
| 2760 | public static final String SCENE_MODE_BARCODE = "barcode"; |
| 2761 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2762 | /** |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2763 | * Capture a scene using high dynamic range imaging techniques. The |
| 2764 | * camera will return an image that has an extended dynamic range |
| 2765 | * compared to a regular capture. Capturing such an image may take |
| 2766 | * longer than a regular capture. |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 2767 | */ |
| 2768 | public static final String SCENE_MODE_HDR = "hdr"; |
| 2769 | |
| 2770 | /** |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2771 | * Auto-focus mode. Applications should call {@link |
| 2772 | * #autoFocus(AutoFocusCallback)} to start the focus in this mode. |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2773 | */ |
| 2774 | public static final String FOCUS_MODE_AUTO = "auto"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2775 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2776 | /** |
| 2777 | * Focus is set at infinity. Applications should not call |
| 2778 | * {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2779 | */ |
| 2780 | public static final String FOCUS_MODE_INFINITY = "infinity"; |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 2781 | |
| 2782 | /** |
| 2783 | * Macro (close-up) focus mode. Applications should call |
| 2784 | * {@link #autoFocus(AutoFocusCallback)} to start the focus in this |
| 2785 | * mode. |
| 2786 | */ |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2787 | public static final String FOCUS_MODE_MACRO = "macro"; |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 2788 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 2789 | /** |
| 2790 | * Focus is fixed. The camera is always in this mode if the focus is not |
| 2791 | * adjustable. If the camera has auto-focus, this mode can fix the |
| 2792 | * focus, which is usually at hyperfocal distance. Applications should |
| 2793 | * not call {@link #autoFocus(AutoFocusCallback)} in this mode. |
| 2794 | */ |
| 2795 | public static final String FOCUS_MODE_FIXED = "fixed"; |
| 2796 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2797 | /** @hide |
| 2798 | * Normal focus mode. Applications should call |
| 2799 | * {@link #autoFocus(AutoFocusCallback)} to start the focus in this |
| 2800 | * mode. |
| 2801 | */ |
| 2802 | public static final String FOCUS_MODE_NORMAL = "normal"; |
| 2803 | |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 2804 | /** |
| 2805 | * Extended depth of field (EDOF). Focusing is done digitally and |
| 2806 | * continuously. Applications should not call {@link |
| 2807 | * #autoFocus(AutoFocusCallback)} in this mode. |
| 2808 | */ |
| 2809 | public static final String FOCUS_MODE_EDOF = "edof"; |
| 2810 | |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2811 | /** |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2812 | * Continuous auto focus mode intended for video recording. The camera |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2813 | * continuously tries to focus. This is the best choice for video |
| 2814 | * recording because the focus changes smoothly . Applications still can |
| 2815 | * call {@link #takePicture(Camera.ShutterCallback, |
| 2816 | * Camera.PictureCallback, Camera.PictureCallback)} in this mode but the |
| 2817 | * 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] | 2818 | * set. |
| 2819 | * |
| 2820 | * <p>Since API level 14, applications can call {@link |
| 2821 | * #autoFocus(AutoFocusCallback)} in this mode. The focus callback will |
| 2822 | * immediately return with a boolean that indicates whether the focus is |
| 2823 | * sharp or not. The focus position is locked after autoFocus call. If |
| 2824 | * applications want to resume the continuous focus, cancelAutoFocus |
| 2825 | * must be called. Restarting the preview will not resume the continuous |
| 2826 | * autofocus. To stop continuous focus, applications should change the |
| 2827 | * focus mode to other modes. |
| 2828 | * |
| 2829 | * @see #FOCUS_MODE_CONTINUOUS_PICTURE |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2830 | */ |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 2831 | public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 2832 | |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2833 | /** |
| 2834 | * Continuous auto focus mode intended for taking pictures. The camera |
| 2835 | * continuously tries to focus. The speed of focus change is more |
| 2836 | * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus |
Wu-cheng Li | 53b3091 | 2011-10-12 19:43:51 +0800 | [diff] [blame] | 2837 | * starts when the parameter is set. |
| 2838 | * |
Wu-cheng Li | 0f4f97b | 2011-10-27 18:07:01 +0800 | [diff] [blame] | 2839 | * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in |
| 2840 | * this mode. If the autofocus is in the middle of scanning, the focus |
| 2841 | * callback will return when it completes. If the autofocus is not |
| 2842 | * scanning, the focus callback will immediately return with a boolean |
| 2843 | * that indicates whether the focus is sharp or not. The apps can then |
| 2844 | * decide if they want to take a picture immediately or to change the |
| 2845 | * focus mode to auto, and run a full autofocus cycle. The focus |
| 2846 | * position is locked after autoFocus call. If applications want to |
| 2847 | * resume the continuous focus, cancelAutoFocus must be called. |
| 2848 | * Restarting the preview will not resume the continuous autofocus. To |
| 2849 | * stop continuous focus, applications should change the focus mode to |
| 2850 | * other modes. |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2851 | * |
| 2852 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | b9ac75d | 2011-08-16 21:14:16 +0800 | [diff] [blame] | 2853 | */ |
| 2854 | public static final String FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture"; |
| 2855 | |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2856 | /** @hide |
| 2857 | * manual focus mode |
| 2858 | */ |
| 2859 | public static final String FOCUS_MODE_MANUAL_POSITION = "manual"; |
| 2860 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 2861 | // Indices for focus distance array. |
| 2862 | /** |
| 2863 | * The array index of near focus distance for use with |
| 2864 | * {@link #getFocusDistances(float[])}. |
| 2865 | */ |
| 2866 | public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; |
| 2867 | |
| 2868 | /** |
| 2869 | * The array index of optimal focus distance for use with |
| 2870 | * {@link #getFocusDistances(float[])}. |
| 2871 | */ |
| 2872 | public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; |
| 2873 | |
| 2874 | /** |
| 2875 | * The array index of far focus distance for use with |
| 2876 | * {@link #getFocusDistances(float[])}. |
| 2877 | */ |
| 2878 | public static final int FOCUS_DISTANCE_FAR_INDEX = 2; |
| 2879 | |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 2880 | /** |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2881 | * The array index of minimum preview fps for use with {@link |
| 2882 | * #getPreviewFpsRange(int[])} or {@link |
| 2883 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2884 | */ |
| 2885 | public static final int PREVIEW_FPS_MIN_INDEX = 0; |
| 2886 | |
| 2887 | /** |
| 2888 | * The array index of maximum preview fps for use with {@link |
| 2889 | * #getPreviewFpsRange(int[])} or {@link |
| 2890 | * #getSupportedPreviewFpsRange()}. |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 2891 | */ |
| 2892 | public static final int PREVIEW_FPS_MAX_INDEX = 1; |
| 2893 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2894 | // Formats for setPreviewFormat and setPictureFormat. |
| 2895 | private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; |
| 2896 | private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2897 | private static final String PIXEL_FORMAT_YUV420SP_ADRENO = "yuv420sp-adreno"; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 2898 | private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 2899 | private static final String PIXEL_FORMAT_YUV420P = "yuv420p"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2900 | private static final String PIXEL_FORMAT_RGB565 = "rgb565"; |
| 2901 | private static final String PIXEL_FORMAT_JPEG = "jpeg"; |
Wu-cheng Li | 70fb908 | 2011-08-02 17:49:50 +0800 | [diff] [blame] | 2902 | private static final String PIXEL_FORMAT_BAYER_RGGB = "bayer-rggb"; |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 2903 | private static final String PIXEL_FORMAT_RAW = "raw"; |
| 2904 | private static final String PIXEL_FORMAT_YV12 = "yv12"; |
| 2905 | private static final String PIXEL_FORMAT_NV12 = "nv12"; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2906 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2907 | /** |
| 2908 | * Order matters: Keys that are {@link #set(String, String) set} later |
| 2909 | * will take precedence over keys that are set earlier (if the two keys |
| 2910 | * conflict with each other). |
| 2911 | * |
| 2912 | * <p>One example is {@link #setPreviewFpsRange(int, int)} , since it |
| 2913 | * conflicts with {@link #setPreviewFrameRate(int)} whichever key is set later |
| 2914 | * is the one that will take precedence. |
| 2915 | * </p> |
| 2916 | */ |
| 2917 | private final LinkedHashMap<String, String> mMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | |
| 2919 | private Parameters() { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 2920 | mMap = new LinkedHashMap<String, String>(/*initialCapacity*/64); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | /** |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2924 | * Overwrite existing parameters with a copy of the ones from {@code other}. |
| 2925 | * |
| 2926 | * <b>For use by the legacy shim only.</b> |
| 2927 | * |
| 2928 | * @hide |
| 2929 | */ |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 2930 | @UnsupportedAppUsage |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2931 | public void copyFrom(Parameters other) { |
| 2932 | if (other == null) { |
| 2933 | throw new NullPointerException("other must not be null"); |
| 2934 | } |
| 2935 | |
| 2936 | mMap.putAll(other.mMap); |
| 2937 | } |
| 2938 | |
| 2939 | private Camera getOuter() { |
| 2940 | return Camera.this; |
| 2941 | } |
| 2942 | |
Ruben Brunk | d1f113d | 2014-07-11 11:46:20 -0700 | [diff] [blame] | 2943 | |
| 2944 | /** |
| 2945 | * Value equality check. |
| 2946 | * |
| 2947 | * @hide |
| 2948 | */ |
| 2949 | public boolean same(Parameters other) { |
| 2950 | if (this == other) { |
| 2951 | return true; |
| 2952 | } |
| 2953 | return other != null && Parameters.this.mMap.equals(other.mMap); |
| 2954 | } |
| 2955 | |
Igor Murashkin | df6242e | 2014-07-01 18:06:13 -0700 | [diff] [blame] | 2956 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | * Writes the current Parameters to the log. |
| 2958 | * @hide |
| 2959 | * @deprecated |
| 2960 | */ |
Igor Murashkin | a1d6627 | 2014-06-20 11:22:11 -0700 | [diff] [blame] | 2961 | @Deprecated |
Mathew Inwood | 5132cc1 | 2018-08-08 15:50:55 +0100 | [diff] [blame] | 2962 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | public void dump() { |
| 2964 | Log.e(TAG, "dump: size=" + mMap.size()); |
| 2965 | for (String k : mMap.keySet()) { |
| 2966 | Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | /** |
| 2971 | * Creates a single string with all the parameters set in |
| 2972 | * this Parameters object. |
| 2973 | * <p>The {@link #unflatten(String)} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2974 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | * @return a String with all values from this Parameters object, in |
| 2976 | * semi-colon delimited key-value pairs |
| 2977 | */ |
| 2978 | public String flatten() { |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 2979 | StringBuilder flattened = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | for (String k : mMap.keySet()) { |
| 2981 | flattened.append(k); |
| 2982 | flattened.append("="); |
| 2983 | flattened.append(mMap.get(k)); |
| 2984 | flattened.append(";"); |
| 2985 | } |
| 2986 | // chop off the extra semicolon at the end |
| 2987 | flattened.deleteCharAt(flattened.length()-1); |
| 2988 | return flattened.toString(); |
| 2989 | } |
| 2990 | |
| 2991 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2992 | * 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] | 2993 | * this Parameters object. |
| 2994 | * <p>The {@link #flatten()} method does the reverse.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 2995 | * |
| 2996 | * @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] | 2997 | * are semi-colon delimited |
| 2998 | */ |
| 2999 | public void unflatten(String flattened) { |
| 3000 | mMap.clear(); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3001 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 3002 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); |
| 3003 | splitter.setString(flattened); |
| 3004 | for (String kv : splitter) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | int pos = kv.indexOf('='); |
| 3006 | if (pos == -1) { |
| 3007 | continue; |
| 3008 | } |
| 3009 | String k = kv.substring(0, pos); |
| 3010 | String v = kv.substring(pos + 1); |
| 3011 | mMap.put(k, v); |
| 3012 | } |
| 3013 | } |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | public void remove(String key) { |
| 3016 | mMap.remove(key); |
| 3017 | } |
| 3018 | |
| 3019 | /** |
| 3020 | * Sets a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3021 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | * @param key the key name for the parameter |
| 3023 | * @param value the String value of the parameter |
| 3024 | */ |
| 3025 | public void set(String key, String value) { |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 3026 | if (key.indexOf('=') != -1 || key.indexOf(';') != -1 || key.indexOf(0) != -1) { |
| 3027 | 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] | 3028 | return; |
| 3029 | } |
Eino-Ville Talvala | cb56923 | 2012-03-12 11:36:58 -0700 | [diff] [blame] | 3030 | if (value.indexOf('=') != -1 || value.indexOf(';') != -1 || value.indexOf(0) != -1) { |
| 3031 | 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] | 3032 | return; |
| 3033 | } |
| 3034 | |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 3035 | put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * Sets an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3040 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | * @param key the key name for the parameter |
| 3042 | * @param value the int value of the parameter |
| 3043 | */ |
| 3044 | public void set(String key, int value) { |
Igor Murashkin | 7d9a8ff | 2014-03-18 18:14:41 -0700 | [diff] [blame] | 3045 | put(key, Integer.toString(value)); |
| 3046 | } |
| 3047 | |
| 3048 | private void put(String key, String value) { |
| 3049 | /* |
| 3050 | * Remove the key if it already exists. |
| 3051 | * |
| 3052 | * This way setting a new value for an already existing key will always move |
| 3053 | * that key to be ordered the latest in the map. |
| 3054 | */ |
| 3055 | mMap.remove(key); |
| 3056 | mMap.put(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | } |
| 3058 | |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3059 | private void set(String key, List<Area> areas) { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 3060 | if (areas == null) { |
| 3061 | set(key, "(0,0,0,0,0)"); |
| 3062 | } else { |
| 3063 | StringBuilder buffer = new StringBuilder(); |
| 3064 | for (int i = 0; i < areas.size(); i++) { |
| 3065 | Area area = areas.get(i); |
| 3066 | Rect rect = area.rect; |
| 3067 | buffer.append('('); |
| 3068 | buffer.append(rect.left); |
| 3069 | buffer.append(','); |
| 3070 | buffer.append(rect.top); |
| 3071 | buffer.append(','); |
| 3072 | buffer.append(rect.right); |
| 3073 | buffer.append(','); |
| 3074 | buffer.append(rect.bottom); |
| 3075 | buffer.append(','); |
| 3076 | buffer.append(area.weight); |
| 3077 | buffer.append(')'); |
| 3078 | if (i != areas.size() - 1) buffer.append(','); |
| 3079 | } |
| 3080 | set(key, buffer.toString()); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3081 | } |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 3082 | } |
| 3083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | /** |
| 3085 | * Returns the value of a String parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3086 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | * @param key the key name for the parameter |
| 3088 | * @return the String value of the parameter |
| 3089 | */ |
| 3090 | public String get(String key) { |
| 3091 | return mMap.get(key); |
| 3092 | } |
| 3093 | |
| 3094 | /** |
| 3095 | * Returns the value of an integer parameter. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3096 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | * @param key the key name for the parameter |
| 3098 | * @return the int value of the parameter |
| 3099 | */ |
| 3100 | public int getInt(String key) { |
| 3101 | return Integer.parseInt(mMap.get(key)); |
| 3102 | } |
| 3103 | |
| 3104 | /** |
Wu-cheng Li | 26274fa | 2011-05-05 14:36:28 +0800 | [diff] [blame] | 3105 | * Sets the dimensions for preview pictures. If the preview has already |
| 3106 | * started, applications should stop the preview first before changing |
| 3107 | * preview size. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3108 | * |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3109 | * The sides of width and height are based on camera orientation. That |
| 3110 | * is, the preview size is the size before it is rotated by display |
| 3111 | * orientation. So applications need to consider the display orientation |
| 3112 | * while setting preview size. For example, suppose the camera supports |
| 3113 | * both 480x320 and 320x480 preview sizes. The application wants a 3:2 |
| 3114 | * preview ratio. If the display orientation is set to 0 or 180, preview |
| 3115 | * size should be set to 480x320. If the display orientation is set to |
| 3116 | * 90 or 270, preview size should be set to 320x480. The display |
| 3117 | * orientation should also be considered while setting picture size and |
| 3118 | * thumbnail size. |
| 3119 | * |
Yin-Chia Yeh | 428256d | 2019-01-23 15:27:47 -0800 | [diff] [blame] | 3120 | * Exception on 176x144 (QCIF) resolution: |
| 3121 | * Camera devices usually have a fixed capability for downscaling from |
| 3122 | * larger resolution to smaller, and the QCIF resolution sometimes |
| 3123 | * is not fully supported due to this limitation on devices with |
| 3124 | * high-resolution image sensors. Therefore, trying to configure a QCIF |
| 3125 | * preview size with any picture or video size larger than 1920x1080 |
| 3126 | * (either width or height) might not be supported, and |
| 3127 | * {@link #setParameters(Camera.Parameters)} might throw a |
| 3128 | * RuntimeException if it is not. |
| 3129 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | * @param width the width of the pictures, in pixels |
| 3131 | * @param height the height of the pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3132 | * @see #setDisplayOrientation(int) |
| 3133 | * @see #getCameraInfo(int, CameraInfo) |
| 3134 | * @see #setPictureSize(int, int) |
| 3135 | * @see #setJpegThumbnailSize(int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | */ |
| 3137 | public void setPreviewSize(int width, int height) { |
| 3138 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3139 | set(KEY_PREVIEW_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | /** |
| 3143 | * Returns the dimensions setting for preview pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3144 | * |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 3145 | * @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] | 3146 | * for the preview picture |
| 3147 | */ |
| 3148 | public Size getPreviewSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3149 | String pair = get(KEY_PREVIEW_SIZE); |
| 3150 | return strToSize(pair); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3154 | * Gets the supported preview sizes. |
| 3155 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3156 | * @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] | 3157 | * with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3158 | */ |
| 3159 | public List<Size> getSupportedPreviewSizes() { |
| 3160 | String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3161 | return splitSize(str); |
| 3162 | } |
| 3163 | |
| 3164 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3165 | * <p>Gets the supported video frame sizes that can be used by |
| 3166 | * MediaRecorder.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 3167 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3168 | * <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] | 3169 | * least one Size and one of the sizes in the returned list must be |
| 3170 | * passed to MediaRecorder.setVideoSize() for camcorder application if |
| 3171 | * camera is used as the video source. In this case, the size of the |
| 3172 | * preview can be different from the resolution of the recorded video |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3173 | * during video recording.</p> |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 3174 | * |
Yin-Chia Yeh | 428256d | 2019-01-23 15:27:47 -0800 | [diff] [blame] | 3175 | * <p>Exception on 176x144 (QCIF) resolution: |
| 3176 | * Camera devices usually have a fixed capability for downscaling from |
| 3177 | * larger resolution to smaller, and the QCIF resolution sometimes |
| 3178 | * is not fully supported due to this limitation on devices with |
| 3179 | * high-resolution image sensors. Therefore, trying to configure a QCIF |
| 3180 | * video resolution with any preview or picture size larger than |
| 3181 | * 1920x1080 (either width or height) might not be supported, and |
| 3182 | * {@link #setParameters(Camera.Parameters)} will throw a |
| 3183 | * RuntimeException if it is not.</p> |
| 3184 | * |
James Dong | dd0b16c | 2010-09-21 16:23:48 -0700 | [diff] [blame] | 3185 | * @return a list of Size object if camera has separate preview and |
| 3186 | * video output; otherwise, null is returned. |
| 3187 | * @see #getPreferredPreviewSizeForVideo() |
| 3188 | */ |
| 3189 | public List<Size> getSupportedVideoSizes() { |
| 3190 | String str = get(KEY_VIDEO_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3191 | return splitSize(str); |
| 3192 | } |
| 3193 | |
| 3194 | /** |
| 3195 | * Returns the preferred or recommended preview size (width and height) |
| 3196 | * in pixels for video recording. Camcorder applications should |
| 3197 | * set the preview size to a value that is not larger than the |
| 3198 | * preferred preview size. In other words, the product of the width |
| 3199 | * and height of the preview size should not be larger than that of |
| 3200 | * the preferred preview size. In addition, we recommend to choose a |
| 3201 | * preview size that has the same aspect ratio as the resolution of |
| 3202 | * video to be recorded. |
| 3203 | * |
| 3204 | * @return the preferred preview size (width and height) in pixels for |
| 3205 | * video recording if getSupportedVideoSizes() does not return |
| 3206 | * null; otherwise, null is returned. |
| 3207 | * @see #getSupportedVideoSizes() |
| 3208 | */ |
| 3209 | public Size getPreferredPreviewSizeForVideo() { |
| 3210 | String pair = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); |
| 3211 | return strToSize(pair); |
| 3212 | } |
| 3213 | |
| 3214 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3215 | * <p>Sets the dimensions for EXIF thumbnail in Jpeg picture. If |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 3216 | * 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] | 3217 | * thumbnail.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3218 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3219 | * <p>Applications need to consider the display orientation. See {@link |
| 3220 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3221 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | * @param width the width of the thumbnail, in pixels |
| 3223 | * @param height the height of the thumbnail, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3224 | * @see #setPreviewSize(int,int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3226 | public void setJpegThumbnailSize(int width, int height) { |
| 3227 | set(KEY_JPEG_THUMBNAIL_WIDTH, width); |
| 3228 | set(KEY_JPEG_THUMBNAIL_HEIGHT, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3232 | * Returns the dimensions for EXIF thumbnail in Jpeg picture. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3234 | * @return a Size object with the height and width setting for the EXIF |
| 3235 | * thumbnails |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3237 | public Size getJpegThumbnailSize() { |
| 3238 | return new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), |
| 3239 | getInt(KEY_JPEG_THUMBNAIL_HEIGHT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /** |
Wu-cheng Li | 4c4300c | 2010-01-23 15:45:39 +0800 | [diff] [blame] | 3243 | * Gets the supported jpeg thumbnail sizes. |
| 3244 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3245 | * @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] | 3246 | * with at least two elements. Size 0,0 (no thumbnail) is always |
| 3247 | * supported. |
| 3248 | */ |
| 3249 | public List<Size> getSupportedJpegThumbnailSizes() { |
| 3250 | String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3251 | return splitSize(str); |
| 3252 | } |
| 3253 | |
| 3254 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3255 | * 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] | 3256 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3257 | * @param quality the JPEG quality of the EXIF thumbnail. The range is 1 |
| 3258 | * to 100, with 100 being the best. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3260 | public void setJpegThumbnailQuality(int quality) { |
| 3261 | set(KEY_JPEG_THUMBNAIL_QUALITY, quality); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3265 | * 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] | 3266 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3267 | * @return the JPEG quality setting of the EXIF thumbnail. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | */ |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3269 | public int getJpegThumbnailQuality() { |
| 3270 | return getInt(KEY_JPEG_THUMBNAIL_QUALITY); |
| 3271 | } |
| 3272 | |
| 3273 | /** |
| 3274 | * Sets Jpeg quality of captured picture. |
| 3275 | * |
| 3276 | * @param quality the JPEG quality of captured picture. The range is 1 |
| 3277 | * to 100, with 100 being the best. |
| 3278 | */ |
| 3279 | public void setJpegQuality(int quality) { |
| 3280 | set(KEY_JPEG_QUALITY, quality); |
| 3281 | } |
| 3282 | |
| 3283 | /** |
| 3284 | * Returns the quality setting for the JPEG picture. |
| 3285 | * |
| 3286 | * @return the JPEG picture quality setting. |
| 3287 | */ |
| 3288 | public int getJpegQuality() { |
| 3289 | return getInt(KEY_JPEG_QUALITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 3293 | * Sets the rate at which preview frames are received. This is the |
| 3294 | * target frame rate. The actual frame rate depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3295 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | * @param fps the frame rate (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3297 | * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3299 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | public void setPreviewFrameRate(int fps) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3301 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | /** |
Wu-cheng Li | a18e901 | 2010-02-10 13:05:29 +0800 | [diff] [blame] | 3305 | * Returns the setting for the rate at which preview frames are |
| 3306 | * received. This is the target frame rate. The actual frame rate |
| 3307 | * depends on the driver. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3308 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | * @return the frame rate setting (frames per second) |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3310 | * @deprecated replaced by {@link #getPreviewFpsRange(int[])} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3312 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | public int getPreviewFrameRate() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3314 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3318 | * Gets the supported preview frame rates. |
| 3319 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3320 | * @return a list of supported preview frame rates. null if preview |
| 3321 | * frame rate setting is not supported. |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3322 | * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3323 | */ |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3324 | @Deprecated |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3325 | public List<Integer> getSupportedPreviewFrameRates() { |
| 3326 | String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 3327 | return splitInt(str); |
| 3328 | } |
| 3329 | |
| 3330 | /** |
Hai Guo | 4a68e3c | 2012-12-05 21:50:28 +0800 | [diff] [blame] | 3331 | * 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] | 3332 | * preview frames received in {@link PreviewCallback}. The minimum and |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3333 | * maximum preview fps must be one of the elements from {@link |
| 3334 | * #getSupportedPreviewFpsRange}. |
| 3335 | * |
| 3336 | * @param min the minimum preview fps (scaled by 1000). |
| 3337 | * @param max the maximum preview fps (scaled by 1000). |
| 3338 | * @throws RuntimeException if fps range is invalid. |
| 3339 | * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback) |
| 3340 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3341 | */ |
| 3342 | public void setPreviewFpsRange(int min, int max) { |
| 3343 | set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | * Returns the current minimum and maximum preview fps. The values are |
| 3348 | * one of the elements returned by {@link #getSupportedPreviewFpsRange}. |
| 3349 | * |
| 3350 | * @return range the minimum and maximum preview fps (scaled by 1000). |
| 3351 | * @see #PREVIEW_FPS_MIN_INDEX |
| 3352 | * @see #PREVIEW_FPS_MAX_INDEX |
| 3353 | * @see #getSupportedPreviewFpsRange() |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3354 | */ |
| 3355 | public void getPreviewFpsRange(int[] range) { |
| 3356 | if (range == null || range.length != 2) { |
| 3357 | throw new IllegalArgumentException( |
Wu-cheng Li | 5f1e69c | 2010-08-18 11:39:12 -0700 | [diff] [blame] | 3358 | "range must be an array with two elements."); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3359 | } |
| 3360 | splitInt(get(KEY_PREVIEW_FPS_RANGE), range); |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * Gets the supported preview fps (frame-per-second) ranges. Each range |
| 3365 | * contains a minimum fps and maximum fps. If minimum fps equals to |
| 3366 | * maximum fps, the camera outputs frames in fixed frame rate. If not, |
| 3367 | * the camera outputs frames in auto frame rate. The actual frame rate |
| 3368 | * fluctuates between the minimum and the maximum. The values are |
| 3369 | * multiplied by 1000 and represented in integers. For example, if frame |
| 3370 | * rate is 26.623 frames per second, the value is 26623. |
| 3371 | * |
| 3372 | * @return a list of supported preview fps ranges. This method returns a |
| 3373 | * list with at least one element. Every element is an int array |
| 3374 | * of two values - minimum fps and maximum fps. The list is |
| 3375 | * sorted from small to large (first by maximum fps and then |
| 3376 | * minimum fps). |
| 3377 | * @see #PREVIEW_FPS_MIN_INDEX |
| 3378 | * @see #PREVIEW_FPS_MAX_INDEX |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 3379 | */ |
| 3380 | public List<int[]> getSupportedPreviewFpsRange() { |
| 3381 | String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); |
| 3382 | return splitRange(str); |
| 3383 | } |
| 3384 | |
| 3385 | /** |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3386 | * Sets the image format for preview pictures. |
Scott Main | da0a56d | 2009-09-10 18:08:37 -0700 | [diff] [blame] | 3387 | * <p>If this is never called, the default format will be |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3388 | * {@link android.graphics.ImageFormat#NV21}, which |
Scott Main | df4578e | 2009-09-10 12:22:07 -0700 | [diff] [blame] | 3389 | * uses the NV21 encoding format.</p> |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3390 | * |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3391 | * <p>Use {@link Parameters#getSupportedPreviewFormats} to get a list of |
| 3392 | * the available preview formats. |
| 3393 | * |
| 3394 | * <p>It is strongly recommended that either |
| 3395 | * {@link android.graphics.ImageFormat#NV21} or |
| 3396 | * {@link android.graphics.ImageFormat#YV12} is used, since |
| 3397 | * they are supported by all camera devices.</p> |
| 3398 | * |
| 3399 | * <p>For YV12, the image buffer that is received is not necessarily |
| 3400 | * tightly packed, as there may be padding at the end of each row of |
| 3401 | * pixel data, as described in |
| 3402 | * {@link android.graphics.ImageFormat#YV12}. For camera callback data, |
| 3403 | * it can be assumed that the stride of the Y and UV data is the |
| 3404 | * smallest possible that meets the alignment requirements. That is, if |
| 3405 | * the preview size is <var>width x height</var>, then the following |
| 3406 | * equations describe the buffer index for the beginning of row |
| 3407 | * <var>y</var> for the Y plane and row <var>c</var> for the U and V |
| 3408 | * planes: |
| 3409 | * |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3410 | * <pre>{@code |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3411 | * yStride = (int) ceil(width / 16.0) * 16; |
| 3412 | * uvStride = (int) ceil( (yStride / 2) / 16.0) * 16; |
| 3413 | * ySize = yStride * height; |
| 3414 | * uvSize = uvStride * height / 2; |
| 3415 | * yRowIndex = yStride * y; |
| 3416 | * uRowIndex = ySize + uvSize + uvStride * c; |
| 3417 | * vRowIndex = ySize + uvStride * c; |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3418 | * size = ySize + uvSize * 2; |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3419 | * } |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 3420 | *</pre> |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3421 | * |
| 3422 | * @param pixel_format the desired preview picture format, defined by |
| 3423 | * one of the {@link android.graphics.ImageFormat} constants. (E.g., |
| 3424 | * <var>ImageFormat.NV21</var> (default), or |
| 3425 | * <var>ImageFormat.YV12</var>) |
| 3426 | * |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3427 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3428 | * @see android.hardware.Camera.Parameters#getSupportedPreviewFormats |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | */ |
| 3430 | public void setPreviewFormat(int pixel_format) { |
| 3431 | String s = cameraFormatForPixelFormat(pixel_format); |
| 3432 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3433 | throw new IllegalArgumentException( |
| 3434 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
| 3436 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3437 | set(KEY_PREVIEW_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | /** |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3441 | * Returns the image format for preview frames got from |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3442 | * {@link PreviewCallback}. |
Wu-cheng Li | 7478ea6 | 2009-09-16 18:52:55 +0800 | [diff] [blame] | 3443 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3444 | * @return the preview format. |
| 3445 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3446 | * @see #setPreviewFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | */ |
| 3448 | public int getPreviewFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3449 | return pixelFormatForCameraFormat(get(KEY_PREVIEW_FORMAT)); |
| 3450 | } |
| 3451 | |
| 3452 | /** |
Wu-cheng Li | f9293e7 | 2011-02-25 13:35:10 +0800 | [diff] [blame] | 3453 | * Gets the supported preview formats. {@link android.graphics.ImageFormat#NV21} |
| 3454 | * is always supported. {@link android.graphics.ImageFormat#YV12} |
| 3455 | * is always supported since API level 12. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3456 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3457 | * @return a list of supported preview formats. This method will always |
| 3458 | * return a list with at least one element. |
| 3459 | * @see android.graphics.ImageFormat |
Eino-Ville Talvala | 9515163 | 2012-05-02 16:21:18 -0700 | [diff] [blame] | 3460 | * @see #setPreviewFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3461 | */ |
| 3462 | public List<Integer> getSupportedPreviewFormats() { |
| 3463 | String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3464 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3465 | for (String s : split(str)) { |
| 3466 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3467 | if (f == ImageFormat.UNKNOWN) continue; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3468 | formats.add(f); |
| 3469 | } |
| 3470 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3474 | * <p>Sets the dimensions for pictures.</p> |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3475 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 3476 | * <p>Applications need to consider the display orientation. See {@link |
| 3477 | * #setPreviewSize(int,int)} for reference.</p> |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3478 | * |
Yin-Chia Yeh | 428256d | 2019-01-23 15:27:47 -0800 | [diff] [blame] | 3479 | * <p>Exception on 176x144 (QCIF) resolution: |
| 3480 | * Camera devices usually have a fixed capability for downscaling from |
| 3481 | * larger resolution to smaller, and the QCIF resolution sometimes |
| 3482 | * is not fully supported due to this limitation on devices with |
| 3483 | * high-resolution image sensors. Therefore, trying to configure a QCIF |
| 3484 | * picture size with any preview or video size larger than 1920x1080 |
| 3485 | * (either width or height) might not be supported, and |
| 3486 | * {@link #setParameters(Camera.Parameters)} might throw a |
| 3487 | * RuntimeException if it is not.</p> |
| 3488 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | * @param width the width for pictures, in pixels |
| 3490 | * @param height the height for pictures, in pixels |
Wu-cheng Li | c157e0c | 2010-10-07 18:36:07 +0800 | [diff] [blame] | 3491 | * @see #setPreviewSize(int,int) |
| 3492 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | */ |
| 3494 | public void setPictureSize(int width, int height) { |
| 3495 | String v = Integer.toString(width) + "x" + Integer.toString(height); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3496 | set(KEY_PICTURE_SIZE, v); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /** |
| 3500 | * Returns the dimension setting for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3501 | * |
| 3502 | * @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] | 3503 | * for pictures |
| 3504 | */ |
| 3505 | public Size getPictureSize() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3506 | String pair = get(KEY_PICTURE_SIZE); |
| 3507 | return strToSize(pair); |
| 3508 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3510 | /** |
| 3511 | * Gets the supported picture sizes. |
| 3512 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3513 | * @return a list of supported picture sizes. This method will always |
| 3514 | * return a list with at least one element. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3515 | */ |
| 3516 | public List<Size> getSupportedPictureSizes() { |
| 3517 | String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 3518 | return splitSize(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | /** |
| 3522 | * Sets the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3523 | * |
| 3524 | * @param pixel_format the desired picture format |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3525 | * (<var>ImageFormat.NV21</var>, |
| 3526 | * <var>ImageFormat.RGB_565</var>, or |
| 3527 | * <var>ImageFormat.JPEG</var>) |
| 3528 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | */ |
| 3530 | public void setPictureFormat(int pixel_format) { |
| 3531 | String s = cameraFormatForPixelFormat(pixel_format); |
| 3532 | if (s == null) { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3533 | throw new IllegalArgumentException( |
| 3534 | "Invalid pixel_format=" + pixel_format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3537 | set(KEY_PICTURE_FORMAT, s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | /** |
| 3541 | * Returns the image format for pictures. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3542 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3543 | * @return the picture format |
| 3544 | * @see android.graphics.ImageFormat |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | */ |
| 3546 | public int getPictureFormat() { |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3547 | return pixelFormatForCameraFormat(get(KEY_PICTURE_FORMAT)); |
| 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * Gets the supported picture formats. |
| 3552 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3553 | * @return supported picture formats. This method will always return a |
| 3554 | * list with at least one element. |
| 3555 | * @see android.graphics.ImageFormat |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3556 | */ |
| 3557 | public List<Integer> getSupportedPictureFormats() { |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3558 | String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); |
| 3559 | ArrayList<Integer> formats = new ArrayList<Integer>(); |
| 3560 | for (String s : split(str)) { |
| 3561 | int f = pixelFormatForCameraFormat(s); |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3562 | if (f == ImageFormat.UNKNOWN) continue; |
Wu-cheng Li | 9c79938 | 2009-12-04 19:59:18 +0800 | [diff] [blame] | 3563 | formats.add(f); |
| 3564 | } |
| 3565 | return formats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | private String cameraFormatForPixelFormat(int pixel_format) { |
| 3569 | switch(pixel_format) { |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3570 | case ImageFormat.NV16: return PIXEL_FORMAT_YUV422SP; |
| 3571 | case ImageFormat.NV21: return PIXEL_FORMAT_YUV420SP; |
| 3572 | case ImageFormat.YUY2: return PIXEL_FORMAT_YUV422I; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3573 | case ImageFormat.YV12: return PIXEL_FORMAT_YUV420P; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3574 | case ImageFormat.RGB_565: return PIXEL_FORMAT_RGB565; |
| 3575 | case ImageFormat.JPEG: return PIXEL_FORMAT_JPEG; |
| 3576 | default: return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | private int pixelFormatForCameraFormat(String format) { |
| 3581 | if (format == null) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3582 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3584 | if (format.equals(PIXEL_FORMAT_YUV422SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3585 | return ImageFormat.NV16; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3587 | if (format.equals(PIXEL_FORMAT_YUV420SP)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3588 | return ImageFormat.NV21; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3589 | |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3590 | if (format.equals(PIXEL_FORMAT_YUV422I)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3591 | return ImageFormat.YUY2; |
Chih-Chung Chang | eb68c46 | 2009-09-18 18:37:44 +0800 | [diff] [blame] | 3592 | |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 3593 | if (format.equals(PIXEL_FORMAT_YUV420P)) |
| 3594 | return ImageFormat.YV12; |
| 3595 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3596 | if (format.equals(PIXEL_FORMAT_RGB565)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3597 | return ImageFormat.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3599 | if (format.equals(PIXEL_FORMAT_JPEG)) |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3600 | return ImageFormat.JPEG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 3602 | return ImageFormat.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | } |
| 3604 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3605 | /** |
Wu-cheng Li | 8969ea1 | 2012-04-20 17:38:09 +0800 | [diff] [blame] | 3606 | * Sets the clockwise rotation angle in degrees relative to the |
| 3607 | * orientation of the camera. This affects the pictures returned from |
| 3608 | * JPEG {@link PictureCallback}. The camera driver may set orientation |
| 3609 | * in the EXIF header without rotating the picture. Or the driver may |
| 3610 | * rotate the picture and the EXIF thumbnail. If the Jpeg picture is |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3611 | * rotated, the orientation in the EXIF header will be missing or 1 (row |
| 3612 | * #0 is top and column #0 is left side). |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3613 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3614 | * <p> |
| 3615 | * If applications want to rotate the picture to match the orientation |
| 3616 | * of what users see, apps should use |
| 3617 | * {@link android.view.OrientationEventListener} and |
| 3618 | * {@link android.hardware.Camera.CameraInfo}. The value from |
| 3619 | * OrientationEventListener is relative to the natural orientation of |
| 3620 | * the device. CameraInfo.orientation is the angle between camera |
| 3621 | * orientation and natural device orientation. The sum of the two is the |
| 3622 | * rotation angle for back-facing camera. The difference of the two is |
| 3623 | * the rotation angle for front-facing camera. Note that the JPEG |
| 3624 | * pictures of front-facing cameras are not mirrored as in preview |
| 3625 | * display. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3626 | * |
Igor Murashkin | a1b02db | 2013-06-11 15:25:20 -0700 | [diff] [blame] | 3627 | * <p> |
| 3628 | * For example, suppose the natural orientation of the device is |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3629 | * portrait. The device is rotated 270 degrees clockwise, so the device |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3630 | * orientation is 270. Suppose a back-facing camera sensor is mounted in |
| 3631 | * landscape and the top side of the camera sensor is aligned with the |
| 3632 | * right edge of the display in natural orientation. So the camera |
| 3633 | * 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] | 3634 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 3635 | * <p>The reference code is as follows. |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3636 | * |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3637 | * <pre> |
Scott Main | 9a10bf0 | 2011-08-24 19:09:48 -0700 | [diff] [blame] | 3638 | * public void onOrientationChanged(int orientation) { |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3639 | * if (orientation == ORIENTATION_UNKNOWN) return; |
| 3640 | * android.hardware.Camera.CameraInfo info = |
| 3641 | * new android.hardware.Camera.CameraInfo(); |
| 3642 | * android.hardware.Camera.getCameraInfo(cameraId, info); |
| 3643 | * orientation = (orientation + 45) / 90 * 90; |
Wu-cheng Li | 2fe6fca | 2010-10-15 14:42:23 +0800 | [diff] [blame] | 3644 | * int rotation = 0; |
| 3645 | * if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { |
| 3646 | * rotation = (info.orientation - orientation + 360) % 360; |
| 3647 | * } else { // back-facing camera |
| 3648 | * rotation = (info.orientation + orientation) % 360; |
| 3649 | * } |
| 3650 | * mParameters.setRotation(rotation); |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3651 | * } |
Eino-Ville Talvala | e0cc55a | 2011-11-08 10:12:09 -0800 | [diff] [blame] | 3652 | * </pre> |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3653 | * |
| 3654 | * @param rotation The rotation angle in degrees relative to the |
| 3655 | * orientation of the camera. Rotation can only be 0, |
| 3656 | * 90, 180 or 270. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3657 | * @throws IllegalArgumentException if rotation value is invalid. |
| 3658 | * @see android.view.OrientationEventListener |
Wu-cheng Li | 2fb818c | 2010-09-13 20:02:01 -0700 | [diff] [blame] | 3659 | * @see #getCameraInfo(int, CameraInfo) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3660 | */ |
| 3661 | public void setRotation(int rotation) { |
| 3662 | if (rotation == 0 || rotation == 90 || rotation == 180 |
| 3663 | || rotation == 270) { |
| 3664 | set(KEY_ROTATION, Integer.toString(rotation)); |
| 3665 | } else { |
| 3666 | throw new IllegalArgumentException( |
| 3667 | "Invalid rotation=" + rotation); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | /** |
| 3672 | * Sets GPS latitude coordinate. This will be stored in JPEG EXIF |
| 3673 | * header. |
| 3674 | * |
| 3675 | * @param latitude GPS latitude coordinate. |
| 3676 | */ |
| 3677 | public void setGpsLatitude(double latitude) { |
| 3678 | set(KEY_GPS_LATITUDE, Double.toString(latitude)); |
| 3679 | } |
| 3680 | |
| 3681 | /** |
| 3682 | * Sets GPS longitude coordinate. This will be stored in JPEG EXIF |
| 3683 | * header. |
| 3684 | * |
| 3685 | * @param longitude GPS longitude coordinate. |
| 3686 | */ |
| 3687 | public void setGpsLongitude(double longitude) { |
| 3688 | set(KEY_GPS_LONGITUDE, Double.toString(longitude)); |
| 3689 | } |
| 3690 | |
| 3691 | /** |
| 3692 | * Sets GPS altitude. This will be stored in JPEG EXIF header. |
| 3693 | * |
| 3694 | * @param altitude GPS altitude in meters. |
| 3695 | */ |
| 3696 | public void setGpsAltitude(double altitude) { |
| 3697 | set(KEY_GPS_ALTITUDE, Double.toString(altitude)); |
| 3698 | } |
| 3699 | |
| 3700 | /** |
| 3701 | * Sets GPS timestamp. This will be stored in JPEG EXIF header. |
| 3702 | * |
| 3703 | * @param timestamp GPS timestamp (UTC in seconds since January 1, |
| 3704 | * 1970). |
| 3705 | */ |
| 3706 | public void setGpsTimestamp(long timestamp) { |
| 3707 | set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); |
| 3708 | } |
| 3709 | |
| 3710 | /** |
Eino-Ville Talvala | d840727 | 2015-11-08 18:27:20 -0800 | [diff] [blame] | 3711 | * Sets GPS processing method. The method will be stored in a UTF-8 string up to 31 bytes |
| 3712 | * long, in the JPEG EXIF header. |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3713 | * |
| 3714 | * @param processing_method The processing method to get this location. |
| 3715 | */ |
| 3716 | public void setGpsProcessingMethod(String processing_method) { |
| 3717 | set(KEY_GPS_PROCESSING_METHOD, processing_method); |
| 3718 | } |
| 3719 | |
| 3720 | /** |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3721 | * Removes GPS latitude, longitude, altitude, and timestamp from the |
| 3722 | * parameters. |
| 3723 | */ |
| 3724 | public void removeGpsData() { |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 3725 | remove(KEY_QC_GPS_LATITUDE_REF); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3726 | remove(KEY_GPS_LATITUDE); |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 3727 | remove(KEY_QC_GPS_LONGITUDE_REF); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3728 | remove(KEY_GPS_LONGITUDE); |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 3729 | remove(KEY_QC_GPS_ALTITUDE_REF); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3730 | remove(KEY_GPS_ALTITUDE); |
| 3731 | remove(KEY_GPS_TIMESTAMP); |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 3732 | remove(KEY_GPS_PROCESSING_METHOD); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /** |
| 3736 | * Gets the current white balance setting. |
| 3737 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3738 | * @return current white balance. null if white balance setting is not |
| 3739 | * supported. |
| 3740 | * @see #WHITE_BALANCE_AUTO |
| 3741 | * @see #WHITE_BALANCE_INCANDESCENT |
| 3742 | * @see #WHITE_BALANCE_FLUORESCENT |
| 3743 | * @see #WHITE_BALANCE_WARM_FLUORESCENT |
| 3744 | * @see #WHITE_BALANCE_DAYLIGHT |
| 3745 | * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT |
| 3746 | * @see #WHITE_BALANCE_TWILIGHT |
| 3747 | * @see #WHITE_BALANCE_SHADE |
| 3748 | * |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3749 | */ |
| 3750 | public String getWhiteBalance() { |
| 3751 | return get(KEY_WHITE_BALANCE); |
| 3752 | } |
| 3753 | |
| 3754 | /** |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3755 | * Sets the white balance. Changing the setting will release the |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3756 | * auto-white balance lock. It is recommended not to change white |
| 3757 | * balance and AWB lock at the same time. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3758 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3759 | * @param value new white balance. |
| 3760 | * @see #getWhiteBalance() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 3761 | * @see #setAutoWhiteBalanceLock(boolean) |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3762 | */ |
| 3763 | public void setWhiteBalance(String value) { |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 3764 | String oldValue = get(KEY_WHITE_BALANCE); |
| 3765 | if (same(value, oldValue)) return; |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3766 | set(KEY_WHITE_BALANCE, value); |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 3767 | set(KEY_AUTO_WHITEBALANCE_LOCK, FALSE); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | /** |
| 3771 | * Gets the supported white balance. |
| 3772 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3773 | * @return a list of supported white balance. null if white balance |
| 3774 | * setting is not supported. |
| 3775 | * @see #getWhiteBalance() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3776 | */ |
| 3777 | public List<String> getSupportedWhiteBalance() { |
| 3778 | String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); |
| 3779 | return split(str); |
| 3780 | } |
| 3781 | |
| 3782 | /** |
| 3783 | * Gets the current color effect setting. |
| 3784 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3785 | * @return current color effect. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3786 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3787 | * @see #EFFECT_NONE |
| 3788 | * @see #EFFECT_MONO |
| 3789 | * @see #EFFECT_NEGATIVE |
| 3790 | * @see #EFFECT_SOLARIZE |
| 3791 | * @see #EFFECT_SEPIA |
| 3792 | * @see #EFFECT_POSTERIZE |
| 3793 | * @see #EFFECT_WHITEBOARD |
| 3794 | * @see #EFFECT_BLACKBOARD |
| 3795 | * @see #EFFECT_AQUA |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3796 | */ |
| 3797 | public String getColorEffect() { |
| 3798 | return get(KEY_EFFECT); |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * Sets the current color effect setting. |
| 3803 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3804 | * @param value new color effect. |
| 3805 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3806 | */ |
| 3807 | public void setColorEffect(String value) { |
| 3808 | set(KEY_EFFECT, value); |
| 3809 | } |
| 3810 | |
| 3811 | /** |
| 3812 | * Gets the supported color effects. |
| 3813 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3814 | * @return a list of supported color effects. null if color effect |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3815 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3816 | * @see #getColorEffect() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3817 | */ |
| 3818 | public List<String> getSupportedColorEffects() { |
| 3819 | String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); |
| 3820 | return split(str); |
| 3821 | } |
| 3822 | |
| 3823 | |
| 3824 | /** |
| 3825 | * Gets the current antibanding setting. |
| 3826 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3827 | * @return current antibanding. null if antibanding setting is not |
| 3828 | * supported. |
| 3829 | * @see #ANTIBANDING_AUTO |
| 3830 | * @see #ANTIBANDING_50HZ |
| 3831 | * @see #ANTIBANDING_60HZ |
| 3832 | * @see #ANTIBANDING_OFF |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3833 | */ |
| 3834 | public String getAntibanding() { |
| 3835 | return get(KEY_ANTIBANDING); |
| 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * Sets the antibanding. |
| 3840 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3841 | * @param antibanding new antibanding value. |
| 3842 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3843 | */ |
| 3844 | public void setAntibanding(String antibanding) { |
| 3845 | set(KEY_ANTIBANDING, antibanding); |
| 3846 | } |
| 3847 | |
| 3848 | /** |
| 3849 | * Gets the supported antibanding values. |
| 3850 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3851 | * @return a list of supported antibanding values. null if antibanding |
| 3852 | * setting is not supported. |
| 3853 | * @see #getAntibanding() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3854 | */ |
| 3855 | public List<String> getSupportedAntibanding() { |
| 3856 | String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); |
| 3857 | return split(str); |
| 3858 | } |
| 3859 | |
| 3860 | /** |
| 3861 | * Gets the current scene mode setting. |
| 3862 | * |
| 3863 | * @return one of SCENE_MODE_XXX string constant. null if scene mode |
| 3864 | * setting is not supported. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3865 | * @see #SCENE_MODE_AUTO |
| 3866 | * @see #SCENE_MODE_ACTION |
| 3867 | * @see #SCENE_MODE_PORTRAIT |
| 3868 | * @see #SCENE_MODE_LANDSCAPE |
| 3869 | * @see #SCENE_MODE_NIGHT |
| 3870 | * @see #SCENE_MODE_NIGHT_PORTRAIT |
| 3871 | * @see #SCENE_MODE_THEATRE |
| 3872 | * @see #SCENE_MODE_BEACH |
| 3873 | * @see #SCENE_MODE_SNOW |
| 3874 | * @see #SCENE_MODE_SUNSET |
| 3875 | * @see #SCENE_MODE_STEADYPHOTO |
| 3876 | * @see #SCENE_MODE_FIREWORKS |
| 3877 | * @see #SCENE_MODE_SPORTS |
| 3878 | * @see #SCENE_MODE_PARTY |
| 3879 | * @see #SCENE_MODE_CANDLELIGHT |
Eino-Ville Talvala | da2f0ea | 2012-09-10 12:03:35 -0700 | [diff] [blame] | 3880 | * @see #SCENE_MODE_BARCODE |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3881 | */ |
| 3882 | public String getSceneMode() { |
| 3883 | return get(KEY_SCENE_MODE); |
| 3884 | } |
| 3885 | |
| 3886 | /** |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 3887 | * Sets the scene mode. Changing scene mode may override other |
| 3888 | * parameters (such as flash mode, focus mode, white balance). For |
| 3889 | * example, suppose originally flash mode is on and supported flash |
| 3890 | * modes are on/off. In night scene mode, both flash mode and supported |
| 3891 | * flash mode may be changed to off. After setting scene mode, |
Wu-cheng Li | 2988ab7 | 2009-09-30 17:08:19 -0700 | [diff] [blame] | 3892 | * applications should call getParameters to know if some parameters are |
| 3893 | * changed. |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3894 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3895 | * @param value scene mode. |
| 3896 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3897 | */ |
| 3898 | public void setSceneMode(String value) { |
| 3899 | set(KEY_SCENE_MODE, value); |
| 3900 | } |
| 3901 | |
| 3902 | /** |
| 3903 | * Gets the supported scene modes. |
| 3904 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3905 | * @return a list of supported scene modes. null if scene mode setting |
| 3906 | * is not supported. |
| 3907 | * @see #getSceneMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3908 | */ |
| 3909 | public List<String> getSupportedSceneModes() { |
| 3910 | String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3911 | return split(str); |
| 3912 | } |
| 3913 | |
| 3914 | /** |
| 3915 | * Gets the current flash mode setting. |
| 3916 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3917 | * @return current flash mode. null if flash mode setting is not |
| 3918 | * supported. |
| 3919 | * @see #FLASH_MODE_OFF |
| 3920 | * @see #FLASH_MODE_AUTO |
| 3921 | * @see #FLASH_MODE_ON |
| 3922 | * @see #FLASH_MODE_RED_EYE |
| 3923 | * @see #FLASH_MODE_TORCH |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3924 | */ |
| 3925 | public String getFlashMode() { |
| 3926 | return get(KEY_FLASH_MODE); |
| 3927 | } |
| 3928 | |
| 3929 | /** |
| 3930 | * Sets the flash mode. |
| 3931 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3932 | * @param value flash mode. |
| 3933 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3934 | */ |
| 3935 | public void setFlashMode(String value) { |
| 3936 | set(KEY_FLASH_MODE, value); |
| 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * Gets the supported flash modes. |
| 3941 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3942 | * @return a list of supported flash modes. null if flash mode setting |
| 3943 | * is not supported. |
| 3944 | * @see #getFlashMode() |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 3945 | */ |
| 3946 | public List<String> getSupportedFlashModes() { |
| 3947 | String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3948 | return split(str); |
| 3949 | } |
| 3950 | |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3951 | /** |
| 3952 | * Gets the current focus mode setting. |
| 3953 | * |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 3954 | * @return current focus mode. This method will always return a non-null |
| 3955 | * value. Applications should call {@link |
| 3956 | * #autoFocus(AutoFocusCallback)} to start the focus if focus |
| 3957 | * mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3958 | * @see #FOCUS_MODE_AUTO |
| 3959 | * @see #FOCUS_MODE_INFINITY |
| 3960 | * @see #FOCUS_MODE_MACRO |
| 3961 | * @see #FOCUS_MODE_FIXED |
Wu-cheng Li | f008f3e | 2010-08-17 13:44:35 -0700 | [diff] [blame] | 3962 | * @see #FOCUS_MODE_EDOF |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 3963 | * @see #FOCUS_MODE_CONTINUOUS_VIDEO |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3964 | */ |
| 3965 | public String getFocusMode() { |
| 3966 | return get(KEY_FOCUS_MODE); |
| 3967 | } |
| 3968 | |
| 3969 | /** |
| 3970 | * Sets the focus mode. |
| 3971 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3972 | * @param value focus mode. |
| 3973 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3974 | */ |
| 3975 | public void setFocusMode(String value) { |
| 3976 | set(KEY_FOCUS_MODE, value); |
| 3977 | } |
| 3978 | |
| 3979 | /** |
| 3980 | * Gets the supported focus modes. |
| 3981 | * |
Wu-cheng Li | 3f4639a | 2010-04-04 15:05:41 +0800 | [diff] [blame] | 3982 | * @return a list of supported focus modes. This method will always |
| 3983 | * return a list with at least one element. |
| 3984 | * @see #getFocusMode() |
Wu-cheng Li | 36322db | 2009-09-18 18:59:21 +0800 | [diff] [blame] | 3985 | */ |
| 3986 | public List<String> getSupportedFocusModes() { |
| 3987 | String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); |
| 3988 | return split(str); |
| 3989 | } |
| 3990 | |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 3991 | /** |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3992 | * Gets the focal length (in millimeter) of the camera. |
| 3993 | * |
Yin-Chia Yeh | bb85e1c | 2018-02-27 11:50:48 -0800 | [diff] [blame] | 3994 | * @return the focal length. Returns -1.0 when the device |
| 3995 | * doesn't report focal length information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 3996 | */ |
| 3997 | public float getFocalLength() { |
| 3998 | return Float.parseFloat(get(KEY_FOCAL_LENGTH)); |
| 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * Gets the horizontal angle of view in degrees. |
| 4003 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 4004 | * @return horizontal angle of view. Returns -1.0 when the device |
| 4005 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 4006 | */ |
| 4007 | public float getHorizontalViewAngle() { |
| 4008 | return Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE)); |
| 4009 | } |
| 4010 | |
| 4011 | /** |
| 4012 | * Gets the vertical angle of view in degrees. |
| 4013 | * |
Yin-Chia Yeh | 564ae82 | 2018-02-08 16:24:27 -0800 | [diff] [blame] | 4014 | * @return vertical angle of view. Returns -1.0 when the device |
| 4015 | * doesn't report view angle information. |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 4016 | */ |
| 4017 | public float getVerticalViewAngle() { |
| 4018 | return Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE)); |
| 4019 | } |
| 4020 | |
| 4021 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4022 | * Gets the current exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4023 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4024 | * @return current exposure compensation index. The range is {@link |
| 4025 | * #getMinExposureCompensation} to {@link |
| 4026 | * #getMaxExposureCompensation}. 0 means exposure is not |
| 4027 | * adjusted. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4028 | */ |
| 4029 | public int getExposureCompensation() { |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4030 | return getInt(KEY_EXPOSURE_COMPENSATION, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4034 | * Sets the exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4035 | * |
Wu-cheng Li | 0402e7d | 2010-02-26 15:04:55 +0800 | [diff] [blame] | 4036 | * @param value exposure compensation index. The valid value range is |
| 4037 | * from {@link #getMinExposureCompensation} (inclusive) to {@link |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4038 | * #getMaxExposureCompensation} (inclusive). 0 means exposure is |
| 4039 | * not adjusted. Application should call |
| 4040 | * getMinExposureCompensation and getMaxExposureCompensation to |
| 4041 | * know if exposure compensation is supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4042 | */ |
| 4043 | public void setExposureCompensation(int value) { |
| 4044 | set(KEY_EXPOSURE_COMPENSATION, value); |
| 4045 | } |
| 4046 | |
| 4047 | /** |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4048 | * Gets the maximum exposure compensation index. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4049 | * |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4050 | * @return maximum exposure compensation index (>=0). If both this |
| 4051 | * method and {@link #getMinExposureCompensation} return 0, |
| 4052 | * exposure compensation is not supported. |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4053 | */ |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4054 | public int getMaxExposureCompensation() { |
| 4055 | return getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0); |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Gets the minimum exposure compensation index. |
| 4060 | * |
| 4061 | * @return minimum exposure compensation index (<=0). If both this |
| 4062 | * method and {@link #getMaxExposureCompensation} return 0, |
| 4063 | * exposure compensation is not supported. |
| 4064 | */ |
| 4065 | public int getMinExposureCompensation() { |
| 4066 | return getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0); |
| 4067 | } |
| 4068 | |
| 4069 | /** |
| 4070 | * Gets the exposure compensation step. |
| 4071 | * |
| 4072 | * @return exposure compensation step. Applications can get EV by |
| 4073 | * multiplying the exposure compensation index and step. Ex: if |
| 4074 | * exposure compensation index is -6 and step is 0.333333333, EV |
| 4075 | * is -2. |
| 4076 | */ |
| 4077 | public float getExposureCompensationStep() { |
| 4078 | return getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0); |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4082 | * <p>Sets the auto-exposure lock state. Applications should check |
| 4083 | * {@link #isAutoExposureLockSupported} before using this method.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4084 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4085 | * <p>If set to true, the camera auto-exposure routine will immediately |
| 4086 | * pause until the lock is set to false. Exposure compensation settings |
| 4087 | * changes will still take effect while auto-exposure is locked.</p> |
| 4088 | * |
| 4089 | * <p>If auto-exposure is already locked, setting this to true again has |
| 4090 | * no effect (the driver will not recalculate exposure values).</p> |
| 4091 | * |
| 4092 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 4093 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4094 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 4095 | * lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4096 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4097 | * <p>Exposure compensation, auto-exposure lock, and auto-white balance |
| 4098 | * lock can be used to capture an exposure-bracketed burst of images, |
| 4099 | * for example.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4100 | * |
| 4101 | * <p>Auto-exposure state, including the lock state, will not be |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4102 | * maintained after camera {@link #release()} is called. Locking |
| 4103 | * auto-exposure after {@link #open()} but before the first call to |
| 4104 | * {@link #startPreview()} will not allow the auto-exposure routine to |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4105 | * run at all, and may result in severely over- or under-exposed |
| 4106 | * images.</p> |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4107 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4108 | * @param toggle new state of the auto-exposure lock. True means that |
| 4109 | * auto-exposure is locked, false means that the auto-exposure |
| 4110 | * routine is free to run normally. |
| 4111 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4112 | * @see #getAutoExposureLock() |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4113 | */ |
| 4114 | public void setAutoExposureLock(boolean toggle) { |
| 4115 | set(KEY_AUTO_EXPOSURE_LOCK, toggle ? TRUE : FALSE); |
| 4116 | } |
| 4117 | |
| 4118 | /** |
| 4119 | * Gets the state of the auto-exposure lock. Applications should check |
| 4120 | * {@link #isAutoExposureLockSupported} before using this method. See |
| 4121 | * {@link #setAutoExposureLock} for details about the lock. |
| 4122 | * |
| 4123 | * @return State of the auto-exposure lock. Returns true if |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4124 | * auto-exposure is currently locked, and false otherwise. |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4125 | * |
| 4126 | * @see #setAutoExposureLock(boolean) |
| 4127 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4128 | */ |
| 4129 | public boolean getAutoExposureLock() { |
| 4130 | String str = get(KEY_AUTO_EXPOSURE_LOCK); |
| 4131 | return TRUE.equals(str); |
| 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * Returns true if auto-exposure locking is supported. Applications |
| 4136 | * should call this before trying to lock auto-exposure. See |
| 4137 | * {@link #setAutoExposureLock} for details about the lock. |
| 4138 | * |
| 4139 | * @return true if auto-exposure lock is supported. |
| 4140 | * @see #setAutoExposureLock(boolean) |
| 4141 | * |
Eino-Ville Talvala | 3773eef | 2011-04-15 13:51:42 -0700 | [diff] [blame] | 4142 | */ |
| 4143 | public boolean isAutoExposureLockSupported() { |
| 4144 | String str = get(KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); |
| 4145 | return TRUE.equals(str); |
| 4146 | } |
| 4147 | |
| 4148 | /** |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4149 | * <p>Sets the auto-white balance lock state. Applications should check |
| 4150 | * {@link #isAutoWhiteBalanceLockSupported} before using this |
| 4151 | * method.</p> |
| 4152 | * |
| 4153 | * <p>If set to true, the camera auto-white balance routine will |
| 4154 | * immediately pause until the lock is set to false.</p> |
| 4155 | * |
| 4156 | * <p>If auto-white balance is already locked, setting this to true |
| 4157 | * again has no effect (the driver will not recalculate white balance |
| 4158 | * values).</p> |
| 4159 | * |
| 4160 | * <p>Stopping preview with {@link #stopPreview()}, or triggering still |
| 4161 | * image capture with {@link #takePicture(Camera.ShutterCallback, |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4162 | * Camera.PictureCallback, Camera.PictureCallback)}, will not change the |
| 4163 | * the lock.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4164 | * |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 4165 | * <p> Changing the white balance mode with {@link #setWhiteBalance} |
| 4166 | * will release the auto-white balance lock if it is set.</p> |
| 4167 | * |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4168 | * <p>Exposure compensation, AE lock, and AWB lock can be used to |
| 4169 | * capture an exposure-bracketed burst of images, for example. |
| 4170 | * Auto-white balance state, including the lock state, will not be |
| 4171 | * maintained after camera {@link #release()} is called. Locking |
| 4172 | * auto-white balance after {@link #open()} but before the first call to |
| 4173 | * {@link #startPreview()} will not allow the auto-white balance routine |
| 4174 | * to run at all, and may result in severely incorrect color in captured |
| 4175 | * images.</p> |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4176 | * |
| 4177 | * @param toggle new state of the auto-white balance lock. True means |
| 4178 | * that auto-white balance is locked, false means that the |
| 4179 | * auto-white balance routine is free to run normally. |
| 4180 | * |
| 4181 | * @see #getAutoWhiteBalanceLock() |
Eino-Ville Talvala | 16b6713 | 2011-08-18 13:57:49 -0700 | [diff] [blame] | 4182 | * @see #setWhiteBalance(String) |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4183 | */ |
| 4184 | public void setAutoWhiteBalanceLock(boolean toggle) { |
| 4185 | set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? TRUE : FALSE); |
| 4186 | } |
| 4187 | |
| 4188 | /** |
| 4189 | * Gets the state of the auto-white balance lock. Applications should |
| 4190 | * check {@link #isAutoWhiteBalanceLockSupported} before using this |
| 4191 | * method. See {@link #setAutoWhiteBalanceLock} for details about the |
| 4192 | * lock. |
| 4193 | * |
| 4194 | * @return State of the auto-white balance lock. Returns true if |
| 4195 | * auto-white balance is currently locked, and false |
Wu-cheng Li | b4f95be | 2011-09-22 11:43:28 +0800 | [diff] [blame] | 4196 | * otherwise. |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4197 | * |
| 4198 | * @see #setAutoWhiteBalanceLock(boolean) |
| 4199 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4200 | */ |
| 4201 | public boolean getAutoWhiteBalanceLock() { |
| 4202 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK); |
| 4203 | return TRUE.equals(str); |
| 4204 | } |
| 4205 | |
| 4206 | /** |
| 4207 | * Returns true if auto-white balance locking is supported. Applications |
| 4208 | * should call this before trying to lock auto-white balance. See |
| 4209 | * {@link #setAutoWhiteBalanceLock} for details about the lock. |
| 4210 | * |
| 4211 | * @return true if auto-white balance lock is supported. |
| 4212 | * @see #setAutoWhiteBalanceLock(boolean) |
| 4213 | * |
Eino-Ville Talvala | d9c2601a | 2011-05-13 10:19:59 -0700 | [diff] [blame] | 4214 | */ |
| 4215 | public boolean isAutoWhiteBalanceLockSupported() { |
| 4216 | String str = get(KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); |
| 4217 | return TRUE.equals(str); |
| 4218 | } |
| 4219 | |
| 4220 | /** |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4221 | * 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] | 4222 | * progress. Applications should check {@link #isZoomSupported} before |
| 4223 | * using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4224 | * |
| 4225 | * @return the current zoom value. The range is 0 to {@link |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4226 | * #getMaxZoom}. 0 means the camera is not zoomed. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4227 | */ |
| 4228 | public int getZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4229 | return getInt(KEY_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4233 | * Sets current zoom value. If the camera is zoomed (value > 0), the |
| 4234 | * actual picture size may be smaller than picture size setting. |
| 4235 | * Applications can check the actual picture size after picture is |
| 4236 | * returned from {@link PictureCallback}. The preview size remains the |
| 4237 | * same in zoom. Applications should check {@link #isZoomSupported} |
| 4238 | * before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4239 | * |
| 4240 | * @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] | 4241 | */ |
| 4242 | public void setZoom(int value) { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4243 | set(KEY_ZOOM, value); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | /** |
| 4247 | * Returns true if zoom is supported. Applications should call this |
| 4248 | * before using other zoom methods. |
| 4249 | * |
| 4250 | * @return true if zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4251 | */ |
| 4252 | public boolean isZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4253 | String str = get(KEY_ZOOM_SUPPORTED); |
| 4254 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | /** |
| 4258 | * Gets the maximum zoom value allowed for snapshot. This is the maximum |
| 4259 | * value that applications can set to {@link #setZoom(int)}. |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4260 | * Applications should call {@link #isZoomSupported} before using this |
| 4261 | * method. This value may change in different preview size. Applications |
| 4262 | * should call this again after setting preview size. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4263 | * |
| 4264 | * @return the maximum zoom value supported by the camera. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4265 | */ |
| 4266 | public int getMaxZoom() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4267 | return getInt(KEY_MAX_ZOOM, 0); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | /** |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4271 | * Gets the zoom ratios of all zoom values. Applications should check |
| 4272 | * {@link #isZoomSupported} before using this method. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4273 | * |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4274 | * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is |
| 4275 | * returned as 320. The number of elements is {@link |
| 4276 | * #getMaxZoom} + 1. The list is sorted from small to large. The |
| 4277 | * first element is always 100. The last element is the zoom |
| 4278 | * ratio of the maximum zoom value. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4279 | */ |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4280 | public List<Integer> getZoomRatios() { |
| 4281 | return splitInt(get(KEY_ZOOM_RATIOS)); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /** |
| 4285 | * Returns true if smooth zoom is supported. Applications should call |
| 4286 | * this before using other smooth zoom methods. |
| 4287 | * |
| 4288 | * @return true if smooth zoom is supported. |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4289 | */ |
| 4290 | public boolean isSmoothZoomSupported() { |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 4291 | String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); |
| 4292 | return TRUE.equals(str); |
Wu-cheng Li | 36f68b8 | 2009-09-28 16:14:58 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4295 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4296 | * <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] | 4297 | * 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] | 4298 | * 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] | 4299 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4300 | * <p>Focus distances may change after calling {@link |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4301 | * #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or {@link |
| 4302 | * #startPreview()}. Applications can call {@link #getParameters()} |
| 4303 | * 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] | 4304 | * focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, focus distances may change |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4305 | * from time to time.</p> |
Wu-cheng Li | 699fe93 | 2010-08-05 11:50:25 -0700 | [diff] [blame] | 4306 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4307 | * <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] | 4308 | * and the subject. After autofocus, the subject distance may be within |
| 4309 | * near and far focus distance. However, the precision depends on the |
| 4310 | * camera hardware, autofocus algorithm, the focus area, and the scene. |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4311 | * 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] | 4312 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4313 | * <p>Far focus distance >= optimal focus distance >= near focus distance. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 4314 | * If the focus distance is infinity, the value will be |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4315 | * {@code Float.POSITIVE_INFINITY}.</p> |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4316 | * |
| 4317 | * @param output focus distances in meters. output must be a float |
| 4318 | * array with three elements. Near focus distance, optimal focus |
| 4319 | * distance, and far focus distance will be filled in the array. |
Wu-cheng Li | 185cc45 | 2010-05-20 15:36:13 +0800 | [diff] [blame] | 4320 | * @see #FOCUS_DISTANCE_NEAR_INDEX |
| 4321 | * @see #FOCUS_DISTANCE_OPTIMAL_INDEX |
| 4322 | * @see #FOCUS_DISTANCE_FAR_INDEX |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4323 | */ |
| 4324 | public void getFocusDistances(float[] output) { |
| 4325 | if (output == null || output.length != 3) { |
| 4326 | throw new IllegalArgumentException( |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 4327 | "output must be a float array with three elements."); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4328 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4329 | splitFloat(get(KEY_FOCUS_DISTANCES), output); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4330 | } |
| 4331 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4332 | /** |
| 4333 | * 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] | 4334 | * length of the list in {@link #setFocusAreas(List)} and |
| 4335 | * {@link #getFocusAreas()}. |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4336 | * |
| 4337 | * @return the maximum number of focus areas supported by the camera. |
| 4338 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4339 | */ |
| 4340 | public int getMaxNumFocusAreas() { |
| 4341 | return getInt(KEY_MAX_NUM_FOCUS_AREAS, 0); |
| 4342 | } |
| 4343 | |
| 4344 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4345 | * <p>Gets the current focus areas. Camera driver uses the areas to decide |
| 4346 | * focus.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4347 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4348 | * <p>Before using this API or {@link #setFocusAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4349 | * call {@link #getMaxNumFocusAreas()} to know the maximum number of |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4350 | * 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] | 4351 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4352 | * <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] | 4353 | * is relative to the sensor orientation, that is, what the sensor sees. |
| 4354 | * The direction is not affected by the rotation or mirroring of |
| 4355 | * {@link #setDisplayOrientation(int)}. Coordinates of the rectangle |
| 4356 | * 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] | 4357 | * (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] | 4358 | * areas cannot be 0 or negative.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4359 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4360 | * <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] | 4361 | * interpreted as a per-pixel weight - all pixels in the area have the |
| 4362 | * specified weight. This means a small area with the same weight as a |
| 4363 | * larger area will have less influence on the focusing than the larger |
| 4364 | * 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] | 4365 | * weights in the overlap region.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4366 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4367 | * <p>A special case of a {@code null} focus area list means the driver is |
| 4368 | * free to select focus targets as it wants. For example, the driver may |
| 4369 | * use more signals to select focus areas and change them |
| 4370 | * dynamically. Apps can set the focus area list to {@code null} if they |
| 4371 | * want the driver to completely control focusing.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4372 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4373 | * <p>Focus areas are relative to the current field of view |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4374 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 4375 | * represents the top of the currently visible camera frame. The focus |
| 4376 | * 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] | 4377 | * when using zoom.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4378 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4379 | * <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] | 4380 | * {@link #FOCUS_MODE_AUTO}, {@link #FOCUS_MODE_MACRO}, |
| 4381 | * {@link #FOCUS_MODE_CONTINUOUS_VIDEO}, or |
| 4382 | * {@link #FOCUS_MODE_CONTINUOUS_PICTURE}.</p> |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4383 | * |
| 4384 | * @return a list of current focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4385 | */ |
| 4386 | public List<Area> getFocusAreas() { |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4387 | return splitArea(get(KEY_FOCUS_AREAS)); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | /** |
| 4391 | * Sets focus areas. See {@link #getFocusAreas()} for documentation. |
| 4392 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4393 | * @param focusAreas the focus areas |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4394 | * @see #getFocusAreas() |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4395 | */ |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4396 | public void setFocusAreas(List<Area> focusAreas) { |
| 4397 | set(KEY_FOCUS_AREAS, focusAreas); |
| 4398 | } |
| 4399 | |
| 4400 | /** |
| 4401 | * Gets the maximum number of metering areas supported. This is the |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4402 | * maximum length of the list in {@link #setMeteringAreas(List)} and |
| 4403 | * {@link #getMeteringAreas()}. |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4404 | * |
| 4405 | * @return the maximum number of metering areas supported by the camera. |
| 4406 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4407 | */ |
| 4408 | public int getMaxNumMeteringAreas() { |
| 4409 | return getInt(KEY_MAX_NUM_METERING_AREAS, 0); |
| 4410 | } |
| 4411 | |
| 4412 | /** |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4413 | * <p>Gets the current metering areas. Camera driver uses these areas to |
| 4414 | * decide exposure.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4415 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4416 | * <p>Before using this API or {@link #setMeteringAreas(List)}, apps should |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4417 | * call {@link #getMaxNumMeteringAreas()} to know the maximum number of |
| 4418 | * 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] | 4419 | * supported.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4420 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4421 | * <p>Each metering area is a rectangle with specified weight. The |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4422 | * direction is relative to the sensor orientation, that is, what the |
| 4423 | * sensor sees. The direction is not affected by the rotation or |
| 4424 | * mirroring of {@link #setDisplayOrientation(int)}. Coordinates of the |
| 4425 | * 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] | 4426 | * 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] | 4427 | * metering areas cannot be 0 or negative.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4428 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4429 | * <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] | 4430 | * every pixel in the area. This means that a large metering area with |
| 4431 | * the same weight as a smaller area will have more effect in the |
| 4432 | * metering result. Metering areas can partially overlap and the driver |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4433 | * will add the weights in the overlap region.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4434 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4435 | * <p>A special case of a {@code null} metering area list means the driver |
| 4436 | * is free to meter as it chooses. For example, the driver may use more |
| 4437 | * signals to select metering areas and change them dynamically. Apps |
| 4438 | * can set the metering area list to {@code null} if they want the |
| 4439 | * driver to completely control metering.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4440 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4441 | * <p>Metering areas are relative to the current field of view |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4442 | * ({@link #getZoom()}). No matter what the zoom level is, (-1000,-1000) |
| 4443 | * represents the top of the currently visible camera frame. The |
| 4444 | * 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] | 4445 | * even when using zoom.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4446 | * |
Eino-Ville Talvala | 32a972c | 2011-06-07 10:34:56 -0700 | [diff] [blame] | 4447 | * <p>No matter what metering areas are, the final exposure are compensated |
| 4448 | * by {@link #setExposureCompensation(int)}.</p> |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4449 | * |
| 4450 | * @return a list of current metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4451 | */ |
| 4452 | public List<Area> getMeteringAreas() { |
Wu-cheng Li | d8aab93 | 2011-06-21 11:50:43 +0800 | [diff] [blame] | 4453 | return splitArea(get(KEY_METERING_AREAS)); |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | /** |
| 4457 | * Sets metering areas. See {@link #getMeteringAreas()} for |
| 4458 | * documentation. |
| 4459 | * |
Wu-cheng Li | 7b1c5c8 | 2011-04-15 19:16:52 +0800 | [diff] [blame] | 4460 | * @param meteringAreas the metering areas |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4461 | * @see #getMeteringAreas() |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 4462 | */ |
| 4463 | public void setMeteringAreas(List<Area> meteringAreas) { |
| 4464 | set(KEY_METERING_AREAS, meteringAreas); |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4465 | } |
| 4466 | |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4467 | /** |
| 4468 | * Gets the maximum number of detected faces supported. This is the |
| 4469 | * maximum length of the list returned from {@link FaceDetectionListener}. |
| 4470 | * If the return value is 0, face detection of the specified type is not |
| 4471 | * supported. |
| 4472 | * |
| 4473 | * @return the maximum number of detected face supported by the camera. |
Joe Fernandez | 464cb21 | 2011-10-04 16:56:47 -0700 | [diff] [blame] | 4474 | * @see #startFaceDetection() |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4475 | */ |
Wu-cheng Li | c0c683b | 2011-08-04 00:11:00 +0800 | [diff] [blame] | 4476 | public int getMaxNumDetectedFaces() { |
| 4477 | return getInt(KEY_MAX_NUM_DETECTED_FACES_HW, 0); |
Wu-cheng Li | 4c2292e | 2011-07-22 02:37:11 +0800 | [diff] [blame] | 4478 | } |
| 4479 | |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4480 | /** |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4481 | * Sets recording mode hint. This tells the camera that the intent of |
| 4482 | * the application is to record videos {@link |
| 4483 | * android.media.MediaRecorder#start()}, not to take still pictures |
| 4484 | * {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, |
| 4485 | * Camera.PictureCallback, Camera.PictureCallback)}. Using this hint can |
| 4486 | * allow MediaRecorder.start() to start faster or with fewer glitches on |
| 4487 | * output. This should be called before starting preview for the best |
| 4488 | * result, but can be changed while the preview is active. The default |
| 4489 | * value is false. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4490 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4491 | * The app can still call takePicture() when the hint is true or call |
| 4492 | * MediaRecorder.start() when the hint is false. But the performance may |
| 4493 | * be worse. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4494 | * |
Wu-cheng Li | 9c53f1c | 2011-08-02 17:26:58 +0800 | [diff] [blame] | 4495 | * @param hint true if the apps intend to record videos using |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4496 | * {@link android.media.MediaRecorder}. |
Wu-cheng Li | 25d8fb5 | 2011-08-02 13:20:36 +0800 | [diff] [blame] | 4497 | */ |
| 4498 | public void setRecordingHint(boolean hint) { |
| 4499 | set(KEY_RECORDING_HINT, hint ? TRUE : FALSE); |
| 4500 | } |
| 4501 | |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4502 | /** |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4503 | * <p>Returns true if video snapshot is supported. That is, applications |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4504 | * can call {@link #takePicture(Camera.ShutterCallback, |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4505 | * Camera.PictureCallback, Camera.PictureCallback, |
| 4506 | * Camera.PictureCallback)} during recording. Applications do not need |
| 4507 | * to call {@link #startPreview()} after taking a picture. The preview |
| 4508 | * will be still active. Other than that, taking a picture during |
| 4509 | * recording is identical to taking a picture normally. All settings and |
| 4510 | * methods related to takePicture work identically. Ex: |
| 4511 | * {@link #getPictureSize()}, {@link #getSupportedPictureSizes()}, |
| 4512 | * {@link #setJpegQuality(int)}, {@link #setRotation(int)}, and etc. The |
| 4513 | * picture will have an EXIF header. {@link #FLASH_MODE_AUTO} and |
| 4514 | * {@link #FLASH_MODE_ON} also still work, but the video will record the |
| 4515 | * flash.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4516 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4517 | * <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] | 4518 | * 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] | 4519 | * callbacks to null to avoid the interrupt of preview display.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4520 | * |
Eino-Ville Talvala | 1cab31a | 2012-11-05 10:33:55 -0800 | [diff] [blame] | 4521 | * <p>Field-of-view of the recorded video may be different from that of the |
| 4522 | * captured pictures. The maximum size of a video snapshot may be |
| 4523 | * smaller than that for regular still captures. If the current picture |
| 4524 | * size is set higher than can be supported by video snapshot, the |
| 4525 | * picture will be captured at the maximum supported size instead.</p> |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4526 | * |
| 4527 | * @return true if video snapshot is supported. |
Wu-cheng Li | 98bb251 | 2011-08-30 21:33:10 +0800 | [diff] [blame] | 4528 | */ |
| 4529 | public boolean isVideoSnapshotSupported() { |
| 4530 | String str = get(KEY_VIDEO_SNAPSHOT_SUPPORTED); |
| 4531 | return TRUE.equals(str); |
| 4532 | } |
| 4533 | |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4534 | /** |
| 4535 | * <p>Enables and disables video stabilization. Use |
| 4536 | * {@link #isVideoStabilizationSupported} to determine if calling this |
| 4537 | * method is valid.</p> |
| 4538 | * |
| 4539 | * <p>Video stabilization reduces the shaking due to the motion of the |
| 4540 | * camera in both the preview stream and in recorded videos, including |
| 4541 | * data received from the preview callback. It does not reduce motion |
| 4542 | * blur in images captured with |
| 4543 | * {@link Camera#takePicture takePicture}.</p> |
| 4544 | * |
| 4545 | * <p>Video stabilization can be enabled and disabled while preview or |
| 4546 | * recording is active, but toggling it may cause a jump in the video |
| 4547 | * stream that may be undesirable in a recorded video.</p> |
| 4548 | * |
| 4549 | * @param toggle Set to true to enable video stabilization, and false to |
| 4550 | * disable video stabilization. |
| 4551 | * @see #isVideoStabilizationSupported() |
| 4552 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4553 | */ |
| 4554 | public void setVideoStabilization(boolean toggle) { |
| 4555 | set(KEY_VIDEO_STABILIZATION, toggle ? TRUE : FALSE); |
| 4556 | } |
| 4557 | |
| 4558 | /** |
| 4559 | * Get the current state of video stabilization. See |
| 4560 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4561 | * |
| 4562 | * @return true if video stabilization is enabled |
| 4563 | * @see #isVideoStabilizationSupported() |
| 4564 | * @see #setVideoStabilization(boolean) |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4565 | */ |
| 4566 | public boolean getVideoStabilization() { |
| 4567 | String str = get(KEY_VIDEO_STABILIZATION); |
| 4568 | return TRUE.equals(str); |
| 4569 | } |
| 4570 | |
| 4571 | /** |
| 4572 | * Returns true if video stabilization is supported. See |
| 4573 | * {@link #setVideoStabilization} for details of video stabilization. |
| 4574 | * |
| 4575 | * @return true if video stabilization is supported |
| 4576 | * @see #setVideoStabilization(boolean) |
| 4577 | * @see #getVideoStabilization() |
Eino-Ville Talvala | 037abb8 | 2011-10-11 12:41:58 -0700 | [diff] [blame] | 4578 | */ |
| 4579 | public boolean isVideoStabilizationSupported() { |
| 4580 | String str = get(KEY_VIDEO_STABILIZATION_SUPPORTED); |
| 4581 | return TRUE.equals(str); |
| 4582 | } |
| 4583 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4584 | // Splits a comma delimited string to an ArrayList of String. |
| 4585 | // Return null if the passing string is null or the size is 0. |
| 4586 | private ArrayList<String> split(String str) { |
| 4587 | if (str == null) return null; |
| 4588 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4589 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4590 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4591 | ArrayList<String> substrings = new ArrayList<String>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4592 | for (String s : splitter) { |
| 4593 | substrings.add(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4594 | } |
| 4595 | return substrings; |
| 4596 | } |
| 4597 | |
| 4598 | // Splits a comma delimited string to an ArrayList of Integer. |
| 4599 | // Return null if the passing string is null or the size is 0. |
| 4600 | private ArrayList<Integer> splitInt(String str) { |
| 4601 | if (str == null) return null; |
| 4602 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4603 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4604 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4605 | ArrayList<Integer> substrings = new ArrayList<Integer>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4606 | for (String s : splitter) { |
| 4607 | substrings.add(Integer.parseInt(s)); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4608 | } |
| 4609 | if (substrings.size() == 0) return null; |
| 4610 | return substrings; |
| 4611 | } |
| 4612 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4613 | private void splitInt(String str, int[] output) { |
| 4614 | if (str == null) return; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4615 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4616 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4617 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4618 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4619 | for (String s : splitter) { |
| 4620 | output[index++] = Integer.parseInt(s); |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4621 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | // Splits a comma delimited string to an ArrayList of Float. |
| 4625 | private void splitFloat(String str, float[] output) { |
| 4626 | if (str == null) return; |
| 4627 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4628 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4629 | splitter.setString(str); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4630 | int index = 0; |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4631 | for (String s : splitter) { |
| 4632 | output[index++] = Float.parseFloat(s); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4633 | } |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 4634 | } |
| 4635 | |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 4636 | // Returns the value of a float parameter. |
| 4637 | private float getFloat(String key, float defaultValue) { |
| 4638 | try { |
| 4639 | return Float.parseFloat(mMap.get(key)); |
| 4640 | } catch (NumberFormatException ex) { |
| 4641 | return defaultValue; |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | // Returns the value of a integer parameter. |
| 4646 | private int getInt(String key, int defaultValue) { |
| 4647 | try { |
| 4648 | return Integer.parseInt(mMap.get(key)); |
| 4649 | } catch (NumberFormatException ex) { |
| 4650 | return defaultValue; |
| 4651 | } |
| 4652 | } |
| 4653 | |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4654 | // Splits a comma delimited string to an ArrayList of Size. |
| 4655 | // Return null if the passing string is null or the size is 0. |
| 4656 | private ArrayList<Size> splitSize(String str) { |
| 4657 | if (str == null) return null; |
| 4658 | |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4659 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 4660 | splitter.setString(str); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4661 | ArrayList<Size> sizeList = new ArrayList<Size>(); |
Ali Utku Selen | 0a12018 | 2011-02-09 14:11:22 +0100 | [diff] [blame] | 4662 | for (String s : splitter) { |
| 4663 | Size size = strToSize(s); |
Wu-cheng Li | 9b6a8ab | 2009-08-17 18:19:25 +0800 | [diff] [blame] | 4664 | if (size != null) sizeList.add(size); |
| 4665 | } |
| 4666 | if (sizeList.size() == 0) return null; |
| 4667 | return sizeList; |
| 4668 | } |
| 4669 | |
| 4670 | // Parses a string (ex: "480x320") to Size object. |
| 4671 | // Return null if the passing string is null. |
| 4672 | private Size strToSize(String str) { |
| 4673 | if (str == null) return null; |
| 4674 | |
| 4675 | int pos = str.indexOf('x'); |
| 4676 | if (pos != -1) { |
| 4677 | String width = str.substring(0, pos); |
| 4678 | String height = str.substring(pos + 1); |
| 4679 | return new Size(Integer.parseInt(width), |
| 4680 | Integer.parseInt(height)); |
| 4681 | } |
| 4682 | Log.e(TAG, "Invalid size parameter string=" + str); |
| 4683 | return null; |
| 4684 | } |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 4685 | |
| 4686 | // Splits a comma delimited string to an ArrayList of int array. |
| 4687 | // Example string: "(10000,26623),(10000,30000)". Return null if the |
| 4688 | // passing string is null or the size is 0. |
| 4689 | private ArrayList<int[]> splitRange(String str) { |
| 4690 | if (str == null || str.charAt(0) != '(' |
| 4691 | || str.charAt(str.length() - 1) != ')') { |
| 4692 | Log.e(TAG, "Invalid range list string=" + str); |
| 4693 | return null; |
| 4694 | } |
| 4695 | |
| 4696 | ArrayList<int[]> rangeList = new ArrayList<int[]>(); |
| 4697 | int endIndex, fromIndex = 1; |
| 4698 | do { |
| 4699 | int[] range = new int[2]; |
| 4700 | endIndex = str.indexOf("),(", fromIndex); |
| 4701 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4702 | splitInt(str.substring(fromIndex, endIndex), range); |
| 4703 | rangeList.add(range); |
| 4704 | fromIndex = endIndex + 3; |
| 4705 | } while (endIndex != str.length() - 1); |
| 4706 | |
| 4707 | if (rangeList.size() == 0) return null; |
| 4708 | return rangeList; |
| 4709 | } |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4710 | |
| 4711 | // Splits a comma delimited string to an ArrayList of Area objects. |
| 4712 | // 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] | 4713 | // 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] | 4714 | @UnsupportedAppUsage |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4715 | private ArrayList<Area> splitArea(String str) { |
| 4716 | if (str == null || str.charAt(0) != '(' |
| 4717 | || str.charAt(str.length() - 1) != ')') { |
| 4718 | Log.e(TAG, "Invalid area string=" + str); |
| 4719 | return null; |
| 4720 | } |
| 4721 | |
| 4722 | ArrayList<Area> result = new ArrayList<Area>(); |
| 4723 | int endIndex, fromIndex = 1; |
| 4724 | int[] array = new int[5]; |
| 4725 | do { |
| 4726 | endIndex = str.indexOf("),(", fromIndex); |
| 4727 | if (endIndex == -1) endIndex = str.length() - 1; |
| 4728 | splitInt(str.substring(fromIndex, endIndex), array); |
| 4729 | Rect rect = new Rect(array[0], array[1], array[2], array[3]); |
| 4730 | result.add(new Area(rect, array[4])); |
| 4731 | fromIndex = endIndex + 3; |
| 4732 | } while (endIndex != str.length() - 1); |
| 4733 | |
| 4734 | if (result.size() == 0) return null; |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4735 | |
| 4736 | if (result.size() == 1) { |
Wu-cheng Li | bde61a5 | 2011-06-07 18:23:14 +0800 | [diff] [blame] | 4737 | Area area = result.get(0); |
Wu-cheng Li | f715bf9 | 2011-04-14 14:04:18 +0800 | [diff] [blame] | 4738 | Rect rect = area.rect; |
| 4739 | if (rect.left == 0 && rect.top == 0 && rect.right == 0 |
| 4740 | && rect.bottom == 0 && area.weight == 0) { |
| 4741 | return null; |
| 4742 | } |
| 4743 | } |
| 4744 | |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 4745 | return result; |
| 4746 | } |
Wu-cheng Li | b838d8d | 2011-11-17 20:12:23 +0800 | [diff] [blame] | 4747 | |
| 4748 | private boolean same(String s1, String s2) { |
| 4749 | if (s1 == null && s2 == null) return true; |
| 4750 | if (s1 != null && s1.equals(s2)) return true; |
| 4751 | return false; |
| 4752 | } |
Sauhard Pande | c44f2d9 | 2015-07-09 14:47:34 -0700 | [diff] [blame] | 4753 | /* ### QC ADD-ONS: START */ |
| 4754 | |
| 4755 | /* ### QC ADDED PARAMETER KEYS*/ |
| 4756 | private static final String KEY_QC_HFR_SIZE = "hfr-size"; |
| 4757 | private static final String KEY_QC_PREVIEW_FRAME_RATE_MODE = "preview-frame-rate-mode"; |
| 4758 | private static final String KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE = "frame-rate-auto"; |
| 4759 | private static final String KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE = "frame-rate-fixed"; |
| 4760 | private static final String KEY_QC_GPS_LATITUDE_REF = "gps-latitude-ref"; |
| 4761 | private static final String KEY_QC_GPS_LONGITUDE_REF = "gps-longitude-ref"; |
| 4762 | private static final String KEY_QC_GPS_ALTITUDE_REF = "gps-altitude-ref"; |
| 4763 | private static final String KEY_QC_GPS_STATUS = "gps-status"; |
| 4764 | private static final String KEY_QC_EXIF_DATETIME = "exif-datetime"; |
| 4765 | private static final String KEY_QC_TOUCH_AF_AEC = "touch-af-aec"; |
| 4766 | private static final String KEY_QC_TOUCH_INDEX_AEC = "touch-index-aec"; |
| 4767 | private static final String KEY_QC_TOUCH_INDEX_AF = "touch-index-af"; |
| 4768 | private static final String KEY_QC_MANUAL_FOCUS_POSITION = "manual-focus-position"; |
| 4769 | private static final String KEY_QC_MANUAL_FOCUS_POS_TYPE = "manual-focus-pos-type"; |
| 4770 | private static final String KEY_QC_SCENE_DETECT = "scene-detect"; |
| 4771 | private static final String KEY_QC_ISO_MODE = "iso"; |
| 4772 | private static final String KEY_QC_EXPOSURE_TIME = "exposure-time"; |
| 4773 | private static final String KEY_QC_MIN_EXPOSURE_TIME = "min-exposure-time"; |
| 4774 | private static final String KEY_QC_MAX_EXPOSURE_TIME = "max-exposure-time"; |
| 4775 | private static final String KEY_QC_LENSSHADE = "lensshade"; |
| 4776 | private static final String KEY_QC_HISTOGRAM = "histogram"; |
| 4777 | private static final String KEY_QC_SKIN_TONE_ENHANCEMENT = "skinToneEnhancement"; |
| 4778 | private static final String KEY_QC_AUTO_EXPOSURE = "auto-exposure"; |
| 4779 | private static final String KEY_QC_SHARPNESS = "sharpness"; |
| 4780 | private static final String KEY_QC_MAX_SHARPNESS = "max-sharpness"; |
| 4781 | private static final String KEY_QC_CONTRAST = "contrast"; |
| 4782 | private static final String KEY_QC_MAX_CONTRAST = "max-contrast"; |
| 4783 | private static final String KEY_QC_SATURATION = "saturation"; |
| 4784 | private static final String KEY_QC_MAX_SATURATION = "max-saturation"; |
| 4785 | private static final String KEY_QC_DENOISE = "denoise"; |
| 4786 | private static final String KEY_QC_CONTINUOUS_AF = "continuous-af"; |
| 4787 | private static final String KEY_QC_SELECTABLE_ZONE_AF = "selectable-zone-af"; |
| 4788 | private static final String KEY_QC_FACE_DETECTION = "face-detection"; |
| 4789 | private static final String KEY_QC_MEMORY_COLOR_ENHANCEMENT = "mce"; |
| 4790 | private static final String KEY_QC_REDEYE_REDUCTION = "redeye-reduction"; |
| 4791 | private static final String KEY_QC_ZSL = "zsl"; |
| 4792 | private static final String KEY_QC_CAMERA_MODE = "camera-mode"; |
| 4793 | private static final String KEY_QC_VIDEO_HIGH_FRAME_RATE = "video-hfr"; |
| 4794 | private static final String KEY_QC_VIDEO_HDR = "video-hdr"; |
| 4795 | private static final String KEY_QC_POWER_MODE = "power-mode"; |
| 4796 | private static final String KEY_QC_POWER_MODE_SUPPORTED = "power-mode-supported"; |
| 4797 | private static final String KEY_QC_WB_MANUAL_CCT = "wb-manual-cct"; |
| 4798 | private static final String KEY_QC_MIN_WB_CCT = "min-wb-cct"; |
| 4799 | private static final String KEY_QC_MAX_WB_CCT = "max-wb-cct"; |
| 4800 | private static final String KEY_QC_AUTO_HDR_ENABLE = "auto-hdr-enable"; |
| 4801 | private static final String KEY_QC_VIDEO_ROTATION = "video-rotation"; |
| 4802 | |
| 4803 | /** @hide |
| 4804 | * KEY_QC_AE_BRACKET_HDR |
| 4805 | **/ |
| 4806 | public static final String KEY_QC_AE_BRACKET_HDR = "ae-bracket-hdr"; |
| 4807 | |
| 4808 | /* ### QC ADDED PARAMETER VALUES*/ |
| 4809 | |
| 4810 | // Values for touch af/aec settings. |
| 4811 | /** @hide |
| 4812 | * TOUCH_AF_AEC_OFF |
| 4813 | **/ |
| 4814 | public static final String TOUCH_AF_AEC_OFF = "touch-off"; |
| 4815 | /** @hide |
| 4816 | * TOUCH_AF_AEC_ON |
| 4817 | **/ |
| 4818 | public static final String TOUCH_AF_AEC_ON = "touch-on"; |
| 4819 | |
| 4820 | // Values for auto exposure settings. |
| 4821 | /** @hide |
| 4822 | * Auto exposure frame-avg |
| 4823 | **/ |
| 4824 | public static final String AUTO_EXPOSURE_FRAME_AVG = "frame-average"; |
| 4825 | /** @hide |
| 4826 | * Auto exposure center weighted |
| 4827 | **/ |
| 4828 | public static final String AUTO_EXPOSURE_CENTER_WEIGHTED = "center-weighted"; |
| 4829 | /** @hide |
| 4830 | * Auto exposure spot metering |
| 4831 | **/ |
| 4832 | public static final String AUTO_EXPOSURE_SPOT_METERING = "spot-metering"; |
| 4833 | |
| 4834 | //Values for ISO settings |
| 4835 | /** @hide |
| 4836 | * ISO_AUTO |
| 4837 | **/ |
| 4838 | public static final String ISO_AUTO = "auto"; |
| 4839 | /** @hide |
| 4840 | * ISO_HJR |
| 4841 | **/ |
| 4842 | public static final String ISO_HJR = "ISO_HJR"; |
| 4843 | /** @hide |
| 4844 | * ISO_100 |
| 4845 | **/ |
| 4846 | public static final String ISO_100 = "ISO100"; |
| 4847 | /** @hide |
| 4848 | * ISO_200 |
| 4849 | **/ |
| 4850 | public static final String ISO_200 = "ISO200"; |
| 4851 | /** @hide |
| 4852 | * ISO_400 |
| 4853 | **/ |
| 4854 | public static final String ISO_400 = "ISO400"; |
| 4855 | /** @hide |
| 4856 | * ISO_800 |
| 4857 | **/ |
| 4858 | public static final String ISO_800 = "ISO800"; |
| 4859 | /** @hide |
| 4860 | * ISO_1600 |
| 4861 | **/ |
| 4862 | public static final String ISO_1600 = "ISO1600"; |
| 4863 | |
| 4864 | /** @hide |
| 4865 | * ISO_3200 |
| 4866 | **/ |
| 4867 | public static final String ISO_3200 = "ISO3200"; |
| 4868 | |
| 4869 | //Values for Lens Shading |
| 4870 | /** @hide |
| 4871 | * LENSSHADE_ENABLE |
| 4872 | **/ |
| 4873 | public static final String LENSSHADE_ENABLE = "enable"; |
| 4874 | /** @hide |
| 4875 | * LENSSHADE_DISABLE |
| 4876 | **/ |
| 4877 | public static final String LENSSHADE_DISABLE= "disable"; |
| 4878 | |
| 4879 | //Values for Histogram |
| 4880 | /** @hide |
| 4881 | * Histogram enable |
| 4882 | **/ |
| 4883 | public static final String HISTOGRAM_ENABLE = "enable"; |
| 4884 | /** @hide |
| 4885 | * Histogram disable |
| 4886 | **/ |
| 4887 | public static final String HISTOGRAM_DISABLE= "disable"; |
| 4888 | |
| 4889 | //Values for Skin Tone Enhancement |
| 4890 | /** @hide |
| 4891 | * SKIN_TONE_ENHANCEMENT_ENABLE |
| 4892 | **/ |
| 4893 | public static final String SKIN_TONE_ENHANCEMENT_ENABLE = "enable"; |
| 4894 | /** @hide |
| 4895 | * SKIN_TONE_ENHANCEMENT_DISABLE |
| 4896 | **/ |
| 4897 | public static final String SKIN_TONE_ENHANCEMENT_DISABLE= "disable"; |
| 4898 | |
| 4899 | // Values for MCE settings. |
| 4900 | /** @hide |
| 4901 | * MCE_ENaBLE |
| 4902 | **/ |
| 4903 | public static final String MCE_ENABLE = "enable"; |
| 4904 | /** @hide |
| 4905 | * MCE_DISABLE |
| 4906 | **/ |
| 4907 | public static final String MCE_DISABLE = "disable"; |
| 4908 | |
| 4909 | // Values for ZSL settings. |
| 4910 | /** @hide |
| 4911 | * ZSL_ON |
| 4912 | **/ |
| 4913 | public static final String ZSL_ON = "on"; |
| 4914 | /** @hide |
| 4915 | * ZSL_OFF |
| 4916 | **/ |
| 4917 | public static final String ZSL_OFF = "off"; |
| 4918 | |
| 4919 | // Values for HDR Bracketing settings. |
| 4920 | |
| 4921 | /** @hide |
| 4922 | * AEC bracketing off |
| 4923 | **/ |
| 4924 | public static final String AE_BRACKET_HDR_OFF = "Off"; |
| 4925 | /** @hide |
| 4926 | * AEC bracketing hdr |
| 4927 | **/ |
| 4928 | public static final String AE_BRACKET_HDR = "HDR"; |
| 4929 | /** @hide |
| 4930 | * AEC bracketing aec-bracket |
| 4931 | **/ |
| 4932 | public static final String AE_BRACKET = "AE-Bracket"; |
| 4933 | |
| 4934 | // Values for Power mode. |
| 4935 | /** @hide |
| 4936 | * LOW_POWER |
| 4937 | **/ |
| 4938 | public static final String LOW_POWER = "Low_Power"; |
| 4939 | /** @hide |
| 4940 | * NORMAL_POWER |
| 4941 | **/ |
| 4942 | public static final String NORMAL_POWER = "Normal_Power"; |
| 4943 | |
| 4944 | // Values for HFR settings. |
| 4945 | /** @hide |
| 4946 | * VIDEO_HFR_OFF |
| 4947 | **/ |
| 4948 | public static final String VIDEO_HFR_OFF = "off"; |
| 4949 | /** @hide |
| 4950 | * VIDEO_HFR_2X |
| 4951 | **/ |
| 4952 | public static final String VIDEO_HFR_2X = "60"; |
| 4953 | /** @hide |
| 4954 | * VIDEO_HFR_3X |
| 4955 | **/ |
| 4956 | public static final String VIDEO_HFR_3X = "90"; |
| 4957 | /** @hide |
| 4958 | * VIDEO_HFR_4X |
| 4959 | **/ |
| 4960 | public static final String VIDEO_HFR_4X = "120"; |
| 4961 | |
| 4962 | // Values for auto scene detection settings. |
| 4963 | /** @hide |
| 4964 | * SCENE_DETECT_OFF |
| 4965 | **/ |
| 4966 | public static final String SCENE_DETECT_OFF = "off"; |
| 4967 | /** @hide |
| 4968 | * SCENE_DETECT_ON |
| 4969 | **/ |
| 4970 | public static final String SCENE_DETECT_ON = "on"; |
| 4971 | |
| 4972 | //Values for Continuous AF |
| 4973 | |
| 4974 | /** @hide |
| 4975 | * CAF off |
| 4976 | **/ |
| 4977 | public static final String CONTINUOUS_AF_OFF = "caf-off"; |
| 4978 | /** @hide |
| 4979 | * CAF on |
| 4980 | **/ |
| 4981 | public static final String CONTINUOUS_AF_ON = "caf-on"; |
| 4982 | /** @hide |
| 4983 | * Denoise off |
| 4984 | **/ |
| 4985 | public static final String DENOISE_OFF = "denoise-off"; |
| 4986 | /** @hide |
| 4987 | * Denoise on |
| 4988 | **/ |
| 4989 | public static final String DENOISE_ON = "denoise-on"; |
| 4990 | |
| 4991 | // Values for Redeye Reduction settings. |
| 4992 | /** @hide |
| 4993 | * REDEYE_REDUCTION_ENABLE |
| 4994 | **/ |
| 4995 | public static final String REDEYE_REDUCTION_ENABLE = "enable"; |
| 4996 | /** @hide |
| 4997 | * REDEYE_REDUCTION_DISABLE |
| 4998 | **/ |
| 4999 | public static final String REDEYE_REDUCTION_DISABLE = "disable"; |
| 5000 | |
| 5001 | // Values for selectable zone af settings. |
| 5002 | /** @hide |
| 5003 | * SELECTABLE_ZONE_AF_AUTO |
| 5004 | **/ |
| 5005 | public static final String SELECTABLE_ZONE_AF_AUTO = "auto"; |
| 5006 | /** @hide |
| 5007 | * SELECTABLE_ZONE_AF_SPOTMETERING |
| 5008 | **/ |
| 5009 | public static final String SELECTABLE_ZONE_AF_SPOTMETERING = "spot-metering"; |
| 5010 | /** @hide |
| 5011 | * SELECTABLE_ZONE_AF_CENTER_WEIGHTED |
| 5012 | **/ |
| 5013 | public static final String SELECTABLE_ZONE_AF_CENTER_WEIGHTED = "center-weighted"; |
| 5014 | /** @hide |
| 5015 | * SELECTABLE_ZONE_AF_FRAME_AVERAGE |
| 5016 | **/ |
| 5017 | public static final String SELECTABLE_ZONE_AF_FRAME_AVERAGE = "frame-average"; |
| 5018 | |
| 5019 | // Values for Face Detection settings. |
| 5020 | /** @hide |
| 5021 | * Face Detection off |
| 5022 | **/ |
| 5023 | public static final String FACE_DETECTION_OFF = "off"; |
| 5024 | /** @hide |
| 5025 | * Face Detction on |
| 5026 | **/ |
| 5027 | public static final String FACE_DETECTION_ON = "on"; |
| 5028 | |
| 5029 | // Values for video rotation settings. |
| 5030 | |
| 5031 | /** @hide |
| 5032 | * VIDEO_ROTATION_0 |
| 5033 | **/ |
| 5034 | public static final String VIDEO_ROTATION_0 = "0"; |
| 5035 | /** @hide |
| 5036 | * VIDEO_ROTATION_90 |
| 5037 | **/ |
| 5038 | public static final String VIDEO_ROTATION_90 = "90"; |
| 5039 | /** @hide |
| 5040 | * VIDEO_ROTATION_180 |
| 5041 | **/ |
| 5042 | public static final String VIDEO_ROTATION_180 = "180"; |
| 5043 | /** @hide |
| 5044 | * VIDEO_ROTATION_270 |
| 5045 | **/ |
| 5046 | public static final String VIDEO_ROTATION_270 = "270"; |
| 5047 | |
| 5048 | /* ### QC ADDED PARAMETER APIS*/ |
| 5049 | /** @hide |
| 5050 | * Gets the supported preview sizes in high frame rate recording mode. |
| 5051 | * |
| 5052 | * @return a list of Size object. This method will always return a list |
| 5053 | * with at least one element. |
| 5054 | */ |
| 5055 | public List<Size> getSupportedHfrSizes() { |
| 5056 | String str = get(KEY_QC_HFR_SIZE + SUPPORTED_VALUES_SUFFIX); |
| 5057 | return splitSize(str); |
| 5058 | } |
| 5059 | |
| 5060 | /** @hide |
| 5061 | * Gets the supported Touch AF/AEC setting. |
| 5062 | * |
| 5063 | * @return a List of TOUCH_AF_AEC_XXX string constants. null if TOUCH AF/AEC |
| 5064 | * setting is not supported. |
| 5065 | * |
| 5066 | */ |
| 5067 | public List<String> getSupportedTouchAfAec() { |
| 5068 | String str = get(KEY_QC_TOUCH_AF_AEC + SUPPORTED_VALUES_SUFFIX); |
| 5069 | return split(str); |
| 5070 | } |
| 5071 | |
| 5072 | /** |
| 5073 | * Gets the supported Touch AF/AEC setting. |
| 5074 | * |
| 5075 | * @return a List of TOUCH_AF_AEC_XXX string constants. null if TOUCH AF/AEC |
| 5076 | * setting is not supported. |
| 5077 | * |
| 5078 | */ |
| 5079 | |
| 5080 | /** @hide |
| 5081 | * Gets the supported frame rate modes. |
| 5082 | * |
| 5083 | * @return a List of FRAME_RATE_XXX_MODE string constant. null if this |
| 5084 | * setting is not supported. |
| 5085 | */ |
| 5086 | public List<String> getSupportedPreviewFrameRateModes() { |
| 5087 | String str = get(KEY_QC_PREVIEW_FRAME_RATE_MODE + SUPPORTED_VALUES_SUFFIX); |
| 5088 | return split(str); |
| 5089 | } |
| 5090 | |
| 5091 | /** @hide |
| 5092 | * Gets the supported auto scene detection modes. |
| 5093 | * |
| 5094 | * @return a List of SCENE_DETECT_XXX string constant. null if scene detection |
| 5095 | * setting is not supported. |
| 5096 | * |
| 5097 | */ |
| 5098 | public List<String> getSupportedSceneDetectModes() { |
| 5099 | String str = get(KEY_QC_SCENE_DETECT + SUPPORTED_VALUES_SUFFIX); |
| 5100 | return split(str); |
| 5101 | } |
| 5102 | |
| 5103 | /** @hide |
| 5104 | * Gets the supported ISO values. |
| 5105 | * |
| 5106 | * @return a List of FLASH_MODE_XXX string constants. null if flash mode |
| 5107 | * setting is not supported. |
| 5108 | */ |
| 5109 | public List<String> getSupportedIsoValues() { |
| 5110 | String str = get(KEY_QC_ISO_MODE + SUPPORTED_VALUES_SUFFIX); |
| 5111 | return split(str); |
| 5112 | } |
| 5113 | |
| 5114 | /** @hide |
| 5115 | * Gets the supported Lensshade modes. |
| 5116 | * |
| 5117 | * @return a List of LENS_MODE_XXX string constants. null if lens mode |
| 5118 | * setting is not supported. |
| 5119 | */ |
| 5120 | public List<String> getSupportedLensShadeModes() { |
| 5121 | String str = get(KEY_QC_LENSSHADE + SUPPORTED_VALUES_SUFFIX); |
| 5122 | return split(str); |
| 5123 | } |
| 5124 | |
| 5125 | /** @hide |
| 5126 | * Gets the supported Histogram modes. |
| 5127 | * |
| 5128 | * @return a List of HISTOGRAM_XXX string constants. null if histogram mode |
| 5129 | * setting is not supported. |
| 5130 | */ |
| 5131 | public List<String> getSupportedHistogramModes() { |
| 5132 | String str = get(KEY_QC_HISTOGRAM + SUPPORTED_VALUES_SUFFIX); |
| 5133 | return split(str); |
| 5134 | } |
| 5135 | |
| 5136 | /** @hide |
| 5137 | * Gets the supported Skin Tone Enhancement modes. |
| 5138 | * |
| 5139 | * @return a List of SKIN_TONE_ENHANCEMENT_XXX string constants. null if skin tone enhancement |
| 5140 | * setting is not supported. |
| 5141 | */ |
| 5142 | public List<String> getSupportedSkinToneEnhancementModes() { |
| 5143 | String str = get(KEY_QC_SKIN_TONE_ENHANCEMENT + SUPPORTED_VALUES_SUFFIX); |
| 5144 | return split(str); |
| 5145 | } |
| 5146 | |
| 5147 | /** @hide |
| 5148 | * Gets the supported auto exposure setting. |
| 5149 | * |
| 5150 | * @return a List of AUTO_EXPOSURE_XXX string constants. null if auto exposure |
| 5151 | * setting is not supported. |
| 5152 | */ |
| 5153 | public List<String> getSupportedAutoexposure() { |
| 5154 | String str = get(KEY_QC_AUTO_EXPOSURE + SUPPORTED_VALUES_SUFFIX); |
| 5155 | return split(str); |
| 5156 | } |
| 5157 | |
| 5158 | /** @hide |
| 5159 | * Gets the supported MCE modes. |
| 5160 | * |
| 5161 | * @return a List of MCE_ENABLE/DISABLE string constants. null if MCE mode |
| 5162 | * setting is not supported. |
| 5163 | */ |
| 5164 | public List<String> getSupportedMemColorEnhanceModes() { |
| 5165 | String str = get(KEY_QC_MEMORY_COLOR_ENHANCEMENT + SUPPORTED_VALUES_SUFFIX); |
| 5166 | return split(str); |
| 5167 | } |
| 5168 | |
| 5169 | /** @hide |
| 5170 | * Gets the supported ZSL modes. |
| 5171 | * |
| 5172 | * @return a List of ZSL_OFF/OFF string constants. null if ZSL mode |
| 5173 | * setting is not supported. |
| 5174 | */ |
| 5175 | public List<String> getSupportedZSLModes() { |
| 5176 | String str = get(KEY_QC_ZSL + SUPPORTED_VALUES_SUFFIX); |
| 5177 | return split(str); |
| 5178 | } |
| 5179 | |
| 5180 | /** @hide |
| 5181 | * Gets the supported Video HDR modes. |
| 5182 | * |
| 5183 | * @return a List of Video HDR_OFF/OFF string constants. null if |
| 5184 | * Video HDR mode setting is not supported. |
| 5185 | */ |
| 5186 | public List<String> getSupportedVideoHDRModes() { |
| 5187 | String str = get(KEY_QC_VIDEO_HDR + SUPPORTED_VALUES_SUFFIX); |
| 5188 | return split(str); |
| 5189 | } |
| 5190 | |
| 5191 | /** @hide |
| 5192 | * Gets the supported HFR modes. |
| 5193 | * |
| 5194 | * @return a List of VIDEO_HFR_XXX string constants. null if hfr mode |
| 5195 | * setting is not supported. |
| 5196 | */ |
| 5197 | public List<String> getSupportedVideoHighFrameRateModes() { |
| 5198 | String str = get(KEY_QC_VIDEO_HIGH_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); |
| 5199 | return split(str); |
| 5200 | } |
| 5201 | |
| 5202 | /** @hide |
| 5203 | * Gets the supported Continuous AF modes. |
| 5204 | * |
| 5205 | * @return a List of CONTINUOUS_AF_XXX string constant. null if continuous AF |
| 5206 | * setting is not supported. |
| 5207 | * |
| 5208 | */ |
| 5209 | public List<String> getSupportedContinuousAfModes() { |
| 5210 | String str = get(KEY_QC_CONTINUOUS_AF + SUPPORTED_VALUES_SUFFIX); |
| 5211 | return split(str); |
| 5212 | } |
| 5213 | |
| 5214 | /** @hide |
| 5215 | * Gets the supported DENOISE modes. |
| 5216 | * |
| 5217 | * @return a List of DENOISE_XXX string constant. null if DENOISE |
| 5218 | * setting is not supported. |
| 5219 | * |
| 5220 | */ |
| 5221 | public List<String> getSupportedDenoiseModes() { |
| 5222 | String str = get(KEY_QC_DENOISE + SUPPORTED_VALUES_SUFFIX); |
| 5223 | return split(str); |
| 5224 | } |
| 5225 | |
| 5226 | /** @hide |
| 5227 | * Gets the supported selectable zone af setting. |
| 5228 | * |
| 5229 | * @return a List of SELECTABLE_ZONE_AF_XXX string constants. null if selectable zone af |
| 5230 | * setting is not supported. |
| 5231 | */ |
| 5232 | public List<String> getSupportedSelectableZoneAf() { |
| 5233 | String str = get(KEY_QC_SELECTABLE_ZONE_AF + SUPPORTED_VALUES_SUFFIX); |
| 5234 | return split(str); |
| 5235 | } |
| 5236 | |
| 5237 | /** @hide |
| 5238 | * Gets the supported face detection modes. |
| 5239 | * |
| 5240 | * @return a List of FACE_DETECTION_XXX string constant. null if face detection |
| 5241 | * setting is not supported. |
| 5242 | * |
| 5243 | */ |
| 5244 | public List<String> getSupportedFaceDetectionModes() { |
| 5245 | String str = get(KEY_QC_FACE_DETECTION + SUPPORTED_VALUES_SUFFIX); |
| 5246 | return split(str); |
| 5247 | } |
| 5248 | |
| 5249 | /** @hide |
| 5250 | * Gets the supported redeye reduction modes. |
| 5251 | * |
| 5252 | * @return a List of REDEYE_REDUCTION_XXX string constant. null if redeye reduction |
| 5253 | * setting is not supported. |
| 5254 | * |
| 5255 | */ |
| 5256 | public List<String> getSupportedRedeyeReductionModes() { |
| 5257 | String str = get(KEY_QC_REDEYE_REDUCTION + SUPPORTED_VALUES_SUFFIX); |
| 5258 | return split(str); |
| 5259 | } |
| 5260 | |
| 5261 | /** @hide |
| 5262 | * Sets GPS altitude reference. This will be stored in JPEG EXIF header. |
| 5263 | * @param altRef reference GPS altitude in meters. |
| 5264 | */ |
| 5265 | public void setGpsAltitudeRef(double altRef) { |
| 5266 | set(KEY_QC_GPS_ALTITUDE_REF, Double.toString(altRef)); |
| 5267 | } |
| 5268 | |
| 5269 | /** @hide |
| 5270 | * Sets GPS Status. This will be stored in JPEG EXIF header. |
| 5271 | * |
| 5272 | * @param status GPS status (UTC in seconds since January 1, |
| 5273 | * 1970). |
| 5274 | */ |
| 5275 | public void setGpsStatus(double status) { |
| 5276 | set(KEY_QC_GPS_STATUS, Double.toString(status)); |
| 5277 | } |
| 5278 | |
| 5279 | /** @hide |
| 5280 | * Sets the touch co-ordinate for Touch AEC. |
| 5281 | * |
| 5282 | * @param x the x co-ordinate of the touch event |
| 5283 | * @param y the y co-ordinate of the touch event |
| 5284 | * |
| 5285 | */ |
| 5286 | public void setTouchIndexAec(int x, int y) { |
| 5287 | String v = Integer.toString(x) + "x" + Integer.toString(y); |
| 5288 | set(KEY_QC_TOUCH_INDEX_AEC, v); |
| 5289 | } |
| 5290 | |
| 5291 | /** @hide |
| 5292 | * Returns the touch co-ordinates of the touch event. |
| 5293 | * |
| 5294 | * @return a Index object with the x and y co-ordinated |
| 5295 | * for the touch event |
| 5296 | * |
| 5297 | */ |
| 5298 | public Coordinate getTouchIndexAec() { |
| 5299 | String pair = get(KEY_QC_TOUCH_INDEX_AEC); |
| 5300 | return strToCoordinate(pair); |
| 5301 | } |
| 5302 | |
| 5303 | /** @hide |
| 5304 | * Sets the touch co-ordinate for Touch AF. |
| 5305 | * |
| 5306 | * @param x the x co-ordinate of the touch event |
| 5307 | * @param y the y co-ordinate of the touch event |
| 5308 | * |
| 5309 | */ |
| 5310 | public void setTouchIndexAf(int x, int y) { |
| 5311 | String v = Integer.toString(x) + "x" + Integer.toString(y); |
| 5312 | set(KEY_QC_TOUCH_INDEX_AF, v); |
| 5313 | } |
| 5314 | |
| 5315 | /** @hide |
| 5316 | * Returns the touch co-ordinates of the touch event. |
| 5317 | * |
| 5318 | * @return a Index object with the x and y co-ordinated |
| 5319 | * for the touch event |
| 5320 | * |
| 5321 | */ |
| 5322 | public Coordinate getTouchIndexAf() { |
| 5323 | String pair = get(KEY_QC_TOUCH_INDEX_AF); |
| 5324 | return strToCoordinate(pair); |
| 5325 | } |
| 5326 | /** @hide |
| 5327 | * Set Sharpness Level |
| 5328 | * |
| 5329 | * @param sharpness level |
| 5330 | */ |
| 5331 | public void setSharpness(int sharpness){ |
| 5332 | if((sharpness < 0) || (sharpness > getMaxSharpness()) ) |
| 5333 | throw new IllegalArgumentException( |
| 5334 | "Invalid Sharpness " + sharpness); |
| 5335 | |
| 5336 | set(KEY_QC_SHARPNESS, String.valueOf(sharpness)); |
| 5337 | } |
| 5338 | |
| 5339 | /** @hide |
| 5340 | * Set Contrast Level |
| 5341 | * |
| 5342 | * @param contrast level |
| 5343 | */ |
| 5344 | public void setContrast(int contrast){ |
| 5345 | if((contrast < 0 ) || (contrast > getMaxContrast())) |
| 5346 | throw new IllegalArgumentException( |
| 5347 | "Invalid Contrast " + contrast); |
| 5348 | |
| 5349 | set(KEY_QC_CONTRAST, String.valueOf(contrast)); |
| 5350 | } |
| 5351 | |
| 5352 | /** @hide |
| 5353 | * Set Saturation Level |
| 5354 | * |
| 5355 | * @param saturation level |
| 5356 | */ |
| 5357 | public void setSaturation(int saturation){ |
| 5358 | if((saturation < 0 ) || (saturation > getMaxSaturation())) |
| 5359 | throw new IllegalArgumentException( |
| 5360 | "Invalid Saturation " + saturation); |
| 5361 | |
| 5362 | set(KEY_QC_SATURATION, String.valueOf(saturation)); |
| 5363 | } |
| 5364 | |
| 5365 | /** @hide |
| 5366 | * @return true if full size video snapshot is supported. |
| 5367 | */ |
| 5368 | public boolean isPowerModeSupported() { |
| 5369 | String str = get(KEY_QC_POWER_MODE_SUPPORTED); |
| 5370 | return TRUE.equals(str); |
| 5371 | } |
| 5372 | |
| 5373 | /** @hide |
| 5374 | * Get Sharpness level |
| 5375 | * |
| 5376 | * @return sharpness level |
| 5377 | */ |
| 5378 | public int getSharpness(){ |
| 5379 | return getInt(KEY_QC_SHARPNESS); |
| 5380 | } |
| 5381 | |
| 5382 | /** @hide |
| 5383 | * Get Max Sharpness Level |
| 5384 | * |
| 5385 | * @return max sharpness level |
| 5386 | */ |
| 5387 | public int getMaxSharpness(){ |
| 5388 | return getInt(KEY_QC_MAX_SHARPNESS); |
| 5389 | } |
| 5390 | |
| 5391 | /** @hide |
| 5392 | * Get Contrast level |
| 5393 | * |
| 5394 | * @return contrast level |
| 5395 | */ |
| 5396 | public int getContrast(){ |
| 5397 | return getInt(KEY_QC_CONTRAST); |
| 5398 | } |
| 5399 | |
| 5400 | /** @hide |
| 5401 | * Get Max Contrast Level |
| 5402 | * |
| 5403 | * @return max contrast level |
| 5404 | */ |
| 5405 | public int getMaxContrast(){ |
| 5406 | return getInt(KEY_QC_MAX_CONTRAST); |
| 5407 | } |
| 5408 | |
| 5409 | /** @hide |
| 5410 | * Get Saturation level |
| 5411 | * |
| 5412 | * @return saturation level |
| 5413 | */ |
| 5414 | public int getSaturation(){ |
| 5415 | return getInt(KEY_QC_SATURATION); |
| 5416 | } |
| 5417 | |
| 5418 | /** @hide |
| 5419 | * Get Max Saturation Level |
| 5420 | * |
| 5421 | * @return max contrast level |
| 5422 | */ |
| 5423 | public int getMaxSaturation(){ |
| 5424 | return getInt(KEY_QC_MAX_SATURATION); |
| 5425 | } |
| 5426 | |
| 5427 | /** @hide |
| 5428 | * Sets GPS latitude reference coordinate. This will be stored in JPEG EXIF |
| 5429 | * header. |
| 5430 | * @param latRef GPS latitude reference coordinate. |
| 5431 | */ |
| 5432 | public void setGpsLatitudeRef(String latRef) { |
| 5433 | set(KEY_QC_GPS_LATITUDE_REF, latRef); |
| 5434 | } |
| 5435 | |
| 5436 | /** @hide |
| 5437 | * Sets GPS longitude reference coordinate. This will be stored in JPEG EXIF |
| 5438 | * header. |
| 5439 | * @param lonRef GPS longitude reference coordinate. |
| 5440 | */ |
| 5441 | public void setGpsLongitudeRef(String lonRef) { |
| 5442 | set(KEY_QC_GPS_LONGITUDE_REF, lonRef); |
| 5443 | } |
| 5444 | |
| 5445 | /** @hide |
| 5446 | * Sets system timestamp. This will be stored in JPEG EXIF header. |
| 5447 | * |
| 5448 | * @param dateTime current timestamp (UTC in seconds since January 1, |
| 5449 | * 1970). |
| 5450 | */ |
| 5451 | public void setExifDateTime(String dateTime) { |
| 5452 | set(KEY_QC_EXIF_DATETIME, dateTime); |
| 5453 | } |
| 5454 | |
| 5455 | /** @hide |
| 5456 | * Gets the current Touch AF/AEC setting. |
| 5457 | * |
| 5458 | * @return one of TOUCH_AF_AEC_XXX string constant. null if Touch AF/AEC |
| 5459 | * setting is not supported. |
| 5460 | * |
| 5461 | */ |
| 5462 | public String getTouchAfAec() { |
| 5463 | return get(KEY_QC_TOUCH_AF_AEC); |
| 5464 | } |
| 5465 | |
| 5466 | /** @hide |
| 5467 | * Sets the current TOUCH AF/AEC setting. |
| 5468 | * |
| 5469 | * @param value TOUCH_AF_AEC_XXX string constants. |
| 5470 | * |
| 5471 | */ |
| 5472 | public void setTouchAfAec(String value) { |
| 5473 | set(KEY_QC_TOUCH_AF_AEC, value); |
| 5474 | } |
| 5475 | |
| 5476 | /** @hide |
| 5477 | * Gets the current redeye reduction setting. |
| 5478 | * |
| 5479 | * @return one of REDEYE_REDUCTION_XXX string constant. null if redeye reduction |
| 5480 | * setting is not supported. |
| 5481 | * |
| 5482 | */ |
| 5483 | public String getRedeyeReductionMode() { |
| 5484 | return get(KEY_QC_REDEYE_REDUCTION); |
| 5485 | } |
| 5486 | |
| 5487 | /** @hide |
| 5488 | * Sets the redeye reduction. Other parameters may be changed after changing |
| 5489 | * redeye reduction. After setting redeye reduction, |
| 5490 | * applications should call getParameters to know if some parameters are |
| 5491 | * changed. |
| 5492 | * |
| 5493 | * @param value REDEYE_REDUCTION_XXX string constants. |
| 5494 | * |
| 5495 | */ |
| 5496 | public void setRedeyeReductionMode(String value) { |
| 5497 | set(KEY_QC_REDEYE_REDUCTION, value); |
| 5498 | } |
| 5499 | |
| 5500 | /** @hide |
| 5501 | * Gets the frame rate mode setting. |
| 5502 | * |
| 5503 | * @return one of FRAME_RATE_XXX_MODE string constant. null if this |
| 5504 | * setting is not supported. |
| 5505 | */ |
| 5506 | public String getPreviewFrameRateMode() { |
| 5507 | return get(KEY_QC_PREVIEW_FRAME_RATE_MODE); |
| 5508 | } |
| 5509 | |
| 5510 | /** @hide |
| 5511 | * Sets the frame rate mode. |
| 5512 | * |
| 5513 | * @param value FRAME_RATE_XXX_MODE string constants. |
| 5514 | */ |
| 5515 | public void setPreviewFrameRateMode(String value) { |
| 5516 | set(KEY_QC_PREVIEW_FRAME_RATE_MODE, value); |
| 5517 | } |
| 5518 | |
| 5519 | /** @hide |
| 5520 | * Gets the current auto scene detection setting. |
| 5521 | * |
| 5522 | * @return one of SCENE_DETECT_XXX string constant. null if auto scene detection |
| 5523 | * setting is not supported. |
| 5524 | * |
| 5525 | */ |
| 5526 | public String getSceneDetectMode() { |
| 5527 | return get(KEY_QC_SCENE_DETECT); |
| 5528 | } |
| 5529 | |
| 5530 | /** @hide |
| 5531 | * Sets the auto scene detect. Other parameters may be changed after changing |
| 5532 | * scene detect. After setting auto scene detection, |
| 5533 | * applications should call getParameters to know if some parameters are |
| 5534 | * changed. |
| 5535 | * |
| 5536 | * @param value SCENE_DETECT_XXX string constants. |
| 5537 | * |
| 5538 | */ |
| 5539 | public void setSceneDetectMode(String value) { |
| 5540 | set(KEY_QC_SCENE_DETECT, value); |
| 5541 | } |
| 5542 | |
| 5543 | /** @hide |
| 5544 | * Gets the current hdr bracketing mode setting. |
| 5545 | * |
| 5546 | * @return current hdr bracketing mode. |
| 5547 | * @see #KEY_AE_BRACKET_OFF |
| 5548 | * @see #KEY_AE_BRACKET_HDR |
| 5549 | * @see #KEY_AE_BRACKET_BRACKATING |
| 5550 | */ |
| 5551 | public String getAEBracket() { |
| 5552 | return get(KEY_QC_AE_BRACKET_HDR); |
| 5553 | } |
| 5554 | |
| 5555 | /** @hide |
| 5556 | * Sets the Power mode. |
| 5557 | * |
| 5558 | * @param value Power mode. |
| 5559 | * @see #getPowerMode() |
| 5560 | */ |
| 5561 | public void setPowerMode(String value) { |
| 5562 | set(KEY_QC_POWER_MODE, value); |
| 5563 | } |
| 5564 | |
| 5565 | /** @hide |
| 5566 | * Gets the current power mode setting. |
| 5567 | * |
| 5568 | * @return current power mode. null if power mode setting is not |
| 5569 | * supported. |
| 5570 | * @see #POWER_MODE_LOW |
| 5571 | * @see #POWER_MODE_NORMAL |
| 5572 | */ |
| 5573 | public String getPowerMode() { |
| 5574 | return get(KEY_QC_POWER_MODE); |
| 5575 | } |
| 5576 | |
| 5577 | /** @hide |
| 5578 | * Set HDR-Bracketing Level |
| 5579 | * |
| 5580 | * @param value HDR-Bracketing |
| 5581 | */ |
| 5582 | public void setAEBracket(String value){ |
| 5583 | set(KEY_QC_AE_BRACKET_HDR, value); |
| 5584 | } |
| 5585 | |
| 5586 | /** @hide |
| 5587 | * Gets the current ISO setting. |
| 5588 | * |
| 5589 | * @return one of ISO_XXX string constant. null if ISO |
| 5590 | * setting is not supported. |
| 5591 | */ |
| 5592 | public String getISOValue() { |
| 5593 | return get(KEY_QC_ISO_MODE); |
| 5594 | } |
| 5595 | |
| 5596 | /** @hide |
| 5597 | * Sets the ISO. |
| 5598 | * |
| 5599 | * @param iso ISO_XXX string constant. |
| 5600 | */ |
| 5601 | public void setISOValue(String iso) { |
| 5602 | set(KEY_QC_ISO_MODE, iso); |
| 5603 | } |
| 5604 | |
| 5605 | /** @hide |
| 5606 | * Sets the exposure time. |
| 5607 | * |
| 5608 | * @param value exposure time. |
| 5609 | */ |
| 5610 | public void setExposureTime(int value) { |
| 5611 | set(KEY_QC_EXPOSURE_TIME, Integer.toString(value)); |
| 5612 | } |
| 5613 | |
| 5614 | /** @hide |
| 5615 | * Gets the current exposure time. |
| 5616 | * |
| 5617 | * @return exposure time. |
| 5618 | */ |
| 5619 | public String getExposureTime() { |
| 5620 | return get(KEY_QC_EXPOSURE_TIME); |
| 5621 | } |
| 5622 | |
| 5623 | /** @hide |
| 5624 | * Gets the min supported exposure time. |
| 5625 | * |
| 5626 | * @return min supported exposure time. |
| 5627 | */ |
| 5628 | public String getMinExposureTime() { |
| 5629 | return get(KEY_QC_MIN_EXPOSURE_TIME); |
| 5630 | } |
| 5631 | |
| 5632 | /** @hide |
| 5633 | * Gets the max supported exposure time. |
| 5634 | * |
| 5635 | * @return max supported exposure time. |
| 5636 | */ |
| 5637 | public String getMaxExposureTime() { |
| 5638 | return get(KEY_QC_MAX_EXPOSURE_TIME); |
| 5639 | } |
| 5640 | |
| 5641 | /** @hide |
| 5642 | * Gets the current LensShade Mode. |
| 5643 | * |
| 5644 | * @return LensShade Mode |
| 5645 | */ |
| 5646 | public String getLensShade() { |
| 5647 | return get(KEY_QC_LENSSHADE); |
| 5648 | } |
| 5649 | |
| 5650 | /** @hide |
| 5651 | * Sets the current LensShade Mode. |
| 5652 | * |
| 5653 | * @return LensShade Mode |
| 5654 | */ |
| 5655 | public void setLensShade(String lensshade) { |
| 5656 | set(KEY_QC_LENSSHADE, lensshade); |
| 5657 | } |
| 5658 | |
| 5659 | /** @hide |
| 5660 | * Gets the current auto exposure setting. |
| 5661 | * |
| 5662 | * @return one of AUTO_EXPOSURE_XXX string constant. null if auto exposure |
| 5663 | * setting is not supported. |
| 5664 | */ |
| 5665 | public String getAutoExposure() { |
| 5666 | return get(KEY_QC_AUTO_EXPOSURE); |
| 5667 | } |
| 5668 | |
| 5669 | /** @hide |
| 5670 | * Sets the current auto exposure setting. |
| 5671 | * |
| 5672 | * @param value AUTO_EXPOSURE_XXX string constants. |
| 5673 | */ |
| 5674 | public void setAutoExposure(String value) { |
| 5675 | set(KEY_QC_AUTO_EXPOSURE, value); |
| 5676 | } |
| 5677 | |
| 5678 | /** @hide |
| 5679 | * Gets the current MCE Mode. |
| 5680 | * |
| 5681 | * @return MCE value |
| 5682 | */ |
| 5683 | public String getMemColorEnhance() { |
| 5684 | return get(KEY_QC_MEMORY_COLOR_ENHANCEMENT); |
| 5685 | } |
| 5686 | |
| 5687 | /** @hide |
| 5688 | * Sets the current MCE Mode. |
| 5689 | * |
| 5690 | * @return MCE Mode |
| 5691 | */ |
| 5692 | public void setMemColorEnhance(String mce) { |
| 5693 | set(KEY_QC_MEMORY_COLOR_ENHANCEMENT, mce); |
| 5694 | } |
| 5695 | |
| 5696 | /** @hide |
| 5697 | * Set white balance manual cct value. |
| 5698 | * |
| 5699 | * @param cct user CCT setting. |
| 5700 | */ |
| 5701 | public void setWBManualCCT(int cct) { |
| 5702 | set(KEY_QC_WB_MANUAL_CCT, Integer.toString(cct)); |
| 5703 | } |
| 5704 | |
| 5705 | /** @hide |
| 5706 | * Gets the WB min supported CCT. |
| 5707 | * |
| 5708 | * @return min cct value. |
| 5709 | */ |
| 5710 | public String getWBMinCCT() { |
| 5711 | return get(KEY_QC_MIN_WB_CCT); |
| 5712 | } |
| 5713 | |
| 5714 | /** @hide |
| 5715 | * Gets the WB max supported CCT. |
| 5716 | * |
| 5717 | * @return max cct value. |
| 5718 | */ |
| 5719 | public String getMaxWBCCT() { |
| 5720 | return get(KEY_QC_MAX_WB_CCT); |
| 5721 | } |
| 5722 | |
| 5723 | /** @hide |
| 5724 | * Gets the current WB CCT. |
| 5725 | * |
| 5726 | * @return CCT value |
| 5727 | */ |
| 5728 | public String getWBCurrentCCT() { |
| 5729 | return get(KEY_QC_WB_MANUAL_CCT); |
| 5730 | } |
| 5731 | |
| 5732 | /** @hide |
| 5733 | * Gets the current ZSL Mode. |
| 5734 | * |
| 5735 | * @return ZSL mode value |
| 5736 | */ |
| 5737 | public String getZSLMode() { |
| 5738 | return get(KEY_QC_ZSL); |
| 5739 | } |
| 5740 | |
| 5741 | /** @hide |
| 5742 | * Sets the current ZSL Mode. ZSL mode is set as a 0th bit in KEY_CAMERA_MODE. |
| 5743 | * |
| 5744 | * @return null |
| 5745 | */ |
| 5746 | public void setZSLMode(String zsl) { |
| 5747 | set(KEY_QC_ZSL, zsl); |
| 5748 | } |
| 5749 | |
| 5750 | /** @hide |
| 5751 | * Sets the current Auto HDR Mode. |
| 5752 | * @ auto_hdr auto hdr string for enable/disable |
| 5753 | * @return null |
| 5754 | */ |
| 5755 | public void setAutoHDRMode(String auto_hdr){ |
| 5756 | set(KEY_QC_AUTO_HDR_ENABLE,auto_hdr); |
| 5757 | } |
| 5758 | |
| 5759 | /** @hide |
| 5760 | * Gets the current Camera Mode Flag. Camera mode includes a |
| 5761 | * flag(byte) which indicates different camera modes. |
| 5762 | * For now support for ZSL added at bit0 |
| 5763 | * |
| 5764 | * @return Camera Mode. |
| 5765 | */ |
| 5766 | public String getCameraMode() { |
| 5767 | return get(KEY_QC_CAMERA_MODE); |
| 5768 | } |
| 5769 | |
| 5770 | /** @hide |
| 5771 | * Sets the current Camera Mode. |
| 5772 | * |
| 5773 | * @return null |
| 5774 | */ |
| 5775 | public void setCameraMode(int cameraMode) { |
| 5776 | set(KEY_QC_CAMERA_MODE, cameraMode); |
| 5777 | } |
| 5778 | |
| 5779 | private static final int MANUAL_FOCUS_POS_TYPE_INDEX = 0; |
| 5780 | private static final int MANUAL_FOCUS_POS_TYPE_DAC = 1; |
| 5781 | /** @hide |
| 5782 | * Set focus position. |
| 5783 | * |
| 5784 | * @param pos user setting of focus position. |
| 5785 | */ |
| 5786 | public void setFocusPosition(int type, int pos) { |
| 5787 | set(KEY_QC_MANUAL_FOCUS_POS_TYPE, Integer.toString(type)); |
| 5788 | set(KEY_QC_MANUAL_FOCUS_POSITION, Integer.toString(pos)); |
| 5789 | } |
| 5790 | |
| 5791 | /** @hide |
| 5792 | * Gets the current focus position. |
| 5793 | * |
| 5794 | * @return current focus position |
| 5795 | */ |
| 5796 | public String getCurrentFocusPosition() { |
| 5797 | return get(KEY_QC_MANUAL_FOCUS_POSITION); |
| 5798 | } |
| 5799 | |
| 5800 | |
| 5801 | /** @hide |
| 5802 | * Gets the current HFR Mode. |
| 5803 | * |
| 5804 | * @return VIDEO_HFR_XXX string constants |
| 5805 | */ |
| 5806 | public String getVideoHighFrameRate() { |
| 5807 | return get(KEY_QC_VIDEO_HIGH_FRAME_RATE); |
| 5808 | } |
| 5809 | |
| 5810 | /** @hide |
| 5811 | * Sets the current HFR Mode. |
| 5812 | * |
| 5813 | * @param hfr VIDEO_HFR_XXX string constants |
| 5814 | */ |
| 5815 | public void setVideoHighFrameRate(String hfr) { |
| 5816 | set(KEY_QC_VIDEO_HIGH_FRAME_RATE, hfr); |
| 5817 | } |
| 5818 | |
| 5819 | /** @hide |
| 5820 | * Gets the current Video HDR Mode. |
| 5821 | * |
| 5822 | * @return Video HDR mode value |
| 5823 | */ |
| 5824 | public String getVideoHDRMode() { |
| 5825 | return get(KEY_QC_VIDEO_HDR); |
| 5826 | } |
| 5827 | |
| 5828 | /** @hide |
| 5829 | * Sets the current Video HDR Mode. |
| 5830 | * |
| 5831 | * @return null |
| 5832 | */ |
| 5833 | public void setVideoHDRMode(String videohdr) { |
| 5834 | set(KEY_QC_VIDEO_HDR, videohdr); |
| 5835 | } |
| 5836 | |
| 5837 | /** @hide |
| 5838 | * Gets the current DENOISE setting. |
| 5839 | * |
| 5840 | * @return one of DENOISE_XXX string constant. null if Denoise |
| 5841 | * setting is not supported. |
| 5842 | * |
| 5843 | */ |
| 5844 | public String getDenoise() { |
| 5845 | return get(KEY_QC_DENOISE); |
| 5846 | } |
| 5847 | |
| 5848 | /** @hide |
| 5849 | * Gets the current Continuous AF setting. |
| 5850 | * |
| 5851 | * @return one of CONTINUOUS_AF_XXX string constant. null if continuous AF |
| 5852 | * setting is not supported. |
| 5853 | * |
| 5854 | */ |
| 5855 | public String getContinuousAf() { |
| 5856 | return get(KEY_QC_CONTINUOUS_AF); |
| 5857 | } |
| 5858 | |
| 5859 | /** @hide |
| 5860 | * Sets the current Denoise mode. |
| 5861 | * @param value DENOISE_XXX string constants. |
| 5862 | * |
| 5863 | */ |
| 5864 | |
| 5865 | public void setDenoise(String value) { |
| 5866 | set(KEY_QC_DENOISE, value); |
| 5867 | } |
| 5868 | |
| 5869 | /** @hide |
| 5870 | * Sets the current Continuous AF mode. |
| 5871 | * @param value CONTINUOUS_AF_XXX string constants. |
| 5872 | * |
| 5873 | */ |
| 5874 | public void setContinuousAf(String value) { |
| 5875 | set(KEY_QC_CONTINUOUS_AF, value); |
| 5876 | } |
| 5877 | |
| 5878 | /** @hide |
| 5879 | * Gets the current selectable zone af setting. |
| 5880 | * |
| 5881 | * @return one of SELECTABLE_ZONE_AF_XXX string constant. null if selectable zone af |
| 5882 | * setting is not supported. |
| 5883 | */ |
| 5884 | public String getSelectableZoneAf() { |
| 5885 | return get(KEY_QC_SELECTABLE_ZONE_AF); |
| 5886 | } |
| 5887 | |
| 5888 | /** @hide |
| 5889 | * Sets the current selectable zone af setting. |
| 5890 | * |
| 5891 | * @param value SELECTABLE_ZONE_AF_XXX string constants. |
| 5892 | */ |
| 5893 | public void setSelectableZoneAf(String value) { |
| 5894 | set(KEY_QC_SELECTABLE_ZONE_AF, value); |
| 5895 | } |
| 5896 | |
| 5897 | /** @hide |
| 5898 | * Gets the current face detection setting. |
| 5899 | * |
| 5900 | * @return one of FACE_DETECTION_XXX string constant. null if face detection |
| 5901 | * setting is not supported. |
| 5902 | * |
| 5903 | */ |
| 5904 | public String getFaceDetectionMode() { |
| 5905 | return get(KEY_QC_FACE_DETECTION); |
| 5906 | } |
| 5907 | |
| 5908 | /** @hide |
| 5909 | * Sets the auto scene detect. Other settings like Touch AF/AEC might be |
| 5910 | * changed after setting face detection. |
| 5911 | * |
| 5912 | * @param value FACE_DETECTION_XXX string constants. |
| 5913 | * |
| 5914 | */ |
| 5915 | public void setFaceDetectionMode(String value) { |
| 5916 | set(KEY_QC_FACE_DETECTION, value); |
| 5917 | } |
| 5918 | |
| 5919 | /** @hide |
| 5920 | * Gets the current video rotation setting. |
| 5921 | * |
| 5922 | * @return one of VIDEO_QC_ROTATION_XXX string constant. null if video rotation |
| 5923 | * setting is not supported. |
| 5924 | */ |
| 5925 | public String getVideoRotation() { |
| 5926 | return get(KEY_QC_VIDEO_ROTATION); |
| 5927 | } |
| 5928 | |
| 5929 | /** @hide |
| 5930 | * Sets the current video rotation setting. |
| 5931 | * |
| 5932 | * @param value VIDEO_QC_ROTATION_XXX string constants. |
| 5933 | */ |
| 5934 | public void setVideoRotation(String value) { |
| 5935 | set(KEY_QC_VIDEO_ROTATION, value); |
| 5936 | } |
| 5937 | /** @hide |
| 5938 | * Gets the supported video rotation modes. |
| 5939 | * |
| 5940 | * @return a List of VIDEO_QC_ROTATION_XXX string constant. null if this |
| 5941 | * setting is not supported. |
| 5942 | */ |
| 5943 | public List<String> getSupportedVideoRotationValues() { |
| 5944 | String str = get(KEY_QC_VIDEO_ROTATION + SUPPORTED_VALUES_SUFFIX); |
| 5945 | return split(str); |
| 5946 | } |
| 5947 | |
| 5948 | // Splits a comma delimited string to an ArrayList of Coordinate. |
| 5949 | // Return null if the passing string is null or the Coordinate is 0. |
| 5950 | private ArrayList<Coordinate> splitCoordinate(String str) { |
| 5951 | if (str == null) return null; |
| 5952 | TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); |
| 5953 | splitter.setString(str); |
| 5954 | ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(); |
| 5955 | for (String s : splitter) { |
| 5956 | Coordinate coordinate = strToCoordinate(s); |
| 5957 | if (coordinate != null) coordinateList.add(coordinate); |
| 5958 | } |
| 5959 | if (coordinateList.size() == 0) return null; |
| 5960 | return coordinateList; |
| 5961 | } |
| 5962 | |
| 5963 | // Parses a string (ex: "500x500") to Coordinate object. |
| 5964 | // Return null if the passing string is null. |
| 5965 | private Coordinate strToCoordinate(String str) { |
| 5966 | if (str == null) return null; |
| 5967 | |
| 5968 | int pos = str.indexOf('x'); |
| 5969 | if (pos != -1) { |
| 5970 | String x = str.substring(0, pos); |
| 5971 | String y = str.substring(pos + 1); |
| 5972 | return new Coordinate(Integer.parseInt(x), |
| 5973 | Integer.parseInt(y)); |
| 5974 | } |
| 5975 | Log.e(TAG, "Invalid Coordinate parameter string=" + str); |
| 5976 | return null; |
| 5977 | } |
| 5978 | /* ### QC ADD-ONS: END */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5979 | }; |
| 5980 | } |