CameraSettings.java revision 8097973089420749dcd1ab4974a629c2466b31cc
1package com.android.ex.camera2.portability; 2 3import android.hardware.Camera; 4 5import java.util.ArrayList; 6import java.util.List; 7import java.util.Map; 8import java.util.TreeMap; 9 10/** 11 * A class which stores the camera settings. 12 */ 13public class CameraSettings { 14 15 protected final Map<String, String> mGeneralSetting = new TreeMap<>(); 16 protected final List<Camera.Area> mMeteringAreas = new ArrayList<>(); 17 protected final List<Camera.Area> mFocusAreas = new ArrayList<>(); 18 protected int mPreviewFpsRangeMin; 19 protected int mPreviewFpsRangeMax; 20 protected int mPreviewFrameRate; 21 protected Size mCurrentPreviewSize; 22 protected Size mCurrentPhotoSize; 23 protected int mJpegCompressQuality; 24 protected float mCurrentZoomRatio; 25 protected int mCurrentZoomIndex; 26 protected float mPhotoRotationDegrees; 27 protected int mExposureCompensationIndex; 28 protected CameraCapabilities.FlashMode mCurrentFlashMode; 29 protected CameraCapabilities.FocusMode mCurrentFocusMode; 30 protected CameraCapabilities.SceneMode mCurrentSceneMode; 31 protected CameraCapabilities.WhiteBalance mWhiteBalance; 32 protected boolean mVideoStabilizationEnabled; 33 protected boolean mAutoExposureLocked; 34 protected boolean mAutoWhiteBalanceLocked; 35 protected GpsData mGpsData; 36 37 /** 38 * An immutable class storing GPS related information. 39 * <p>It's a hack since we always use GPS time stamp but does not use other 40 * fields sometimes. Setting processing method to null means the other 41 * fields should not be used.</p> 42 */ 43 public static class GpsData { 44 public final double latitude; 45 public final double longitude; 46 public final double altitude; 47 public final long timeStamp; 48 public final String processingMethod; 49 50 /** Constructor. */ 51 public GpsData(double latitude, double longitude, double altitude, long timeStamp, 52 String processingMethod) { 53 this.latitude = latitude; 54 this.longitude = longitude; 55 this.altitude = altitude; 56 this.timeStamp = timeStamp; 57 this.processingMethod = processingMethod; 58 } 59 60 /** Copy constructor. */ 61 public GpsData(GpsData src) { 62 this.latitude = src.latitude; 63 this.longitude = src.longitude; 64 this.altitude = src.altitude; 65 this.timeStamp = src.timeStamp; 66 this.processingMethod = src.processingMethod; 67 } 68 } 69 70 protected CameraSettings() { 71 } 72 73 /** 74 * Copy constructor. 75 * 76 * @param src The source settings. 77 * @return The copy of the source. 78 */ 79 public CameraSettings(CameraSettings src) { 80 mGeneralSetting.putAll(src.mGeneralSetting); 81 mMeteringAreas.addAll(src.mMeteringAreas); 82 mFocusAreas.addAll(src.mFocusAreas); 83 mPreviewFpsRangeMin = src.mPreviewFpsRangeMin; 84 mPreviewFpsRangeMax = src.mPreviewFpsRangeMax; 85 mPreviewFrameRate = src.mPreviewFrameRate; 86 mCurrentPreviewSize = 87 (src.mCurrentPreviewSize == null ? null : new Size(src.mCurrentPreviewSize)); 88 mCurrentPhotoSize = 89 (src.mCurrentPhotoSize == null ? null : new Size(src.mCurrentPhotoSize)); 90 mJpegCompressQuality = src.mJpegCompressQuality; 91 mCurrentZoomRatio = src.mCurrentZoomRatio; 92 mCurrentZoomIndex = src.mCurrentZoomIndex; 93 mPhotoRotationDegrees = src.mPhotoRotationDegrees; 94 mExposureCompensationIndex = src.mExposureCompensationIndex; 95 mCurrentFlashMode = src.mCurrentFlashMode; 96 mCurrentFocusMode = src.mCurrentFocusMode; 97 mCurrentSceneMode = src.mCurrentSceneMode; 98 mWhiteBalance = src.mWhiteBalance; 99 mVideoStabilizationEnabled = src.mVideoStabilizationEnabled; 100 mAutoExposureLocked = src.mAutoExposureLocked; 101 mAutoWhiteBalanceLocked = src.mAutoWhiteBalanceLocked; 102 mGpsData = src.mGpsData; 103 } 104 105 /** General setting **/ 106 @Deprecated 107 public void setSetting(String key, String value) { 108 mGeneralSetting.put(key, value); 109 } 110 111 /** Preview **/ 112 113 /** 114 * Sets the preview FPS range. This call will invalidate prior calls to 115 * {@link #setPreviewFrameRate(int)}. 116 * 117 * @param min The min FPS. 118 * @param max The max FPS. 119 */ 120 public void setPreviewFpsRange(int min, int max) { 121 if (min > max) { 122 int temp = max; 123 max = min; 124 min = temp; 125 } 126 mPreviewFpsRangeMax = max; 127 mPreviewFpsRangeMin = min; 128 mPreviewFrameRate = -1; 129 } 130 131 /** 132 * @return The min of the preview FPS range. 133 */ 134 public int getPreviewFpsRangeMin() { 135 return mPreviewFpsRangeMin; 136 } 137 138 /** 139 * @return The max of the preview FPS range. 140 */ 141 public int getPreviewFpsRangeMax() { 142 return mPreviewFpsRangeMax; 143 } 144 145 /** 146 * Sets the preview FPS. This call will invalidate prior calls to 147 * {@link #setPreviewFpsRange(int, int)}. 148 * 149 * @param frameRate The target frame rate. 150 */ 151 public void setPreviewFrameRate(int frameRate) { 152 if (frameRate > 0) { 153 mPreviewFrameRate = frameRate; 154 mPreviewFpsRangeMax = frameRate; 155 mPreviewFpsRangeMin = frameRate; 156 } 157 } 158 159 public int getPreviewFrameRate() { 160 return mPreviewFrameRate; 161 } 162 163 /** 164 * @return The current preview size. 165 */ 166 public Size getCurrentPreviewSize() { 167 return new Size(mCurrentPreviewSize); 168 } 169 170 /** 171 * @param previewSize The size to use for preview. 172 */ 173 public void setPreviewSize(Size previewSize) { 174 mCurrentPreviewSize = new Size(previewSize); 175 } 176 177 /** Picture **/ 178 179 /** 180 * @return The current photo size. 181 */ 182 public Size getCurrentPhotoSize() { 183 return new Size(mCurrentPhotoSize); 184 } 185 186 /** 187 * Sets the size for the photo. 188 * 189 * @param photoSize The photo size. 190 */ 191 public void setPhotoSize(Size photoSize) { 192 mCurrentPhotoSize = new Size(photoSize); 193 } 194 195 /** 196 * Sets the JPEG compression quality. 197 * 198 * @param quality The quality for JPEG. 199 */ 200 public void setPhotoJpegCompressionQuality(int quality) { 201 mJpegCompressQuality = quality; 202 } 203 204 public int getPhotoJpegCompressionQuality() { 205 return mJpegCompressQuality; 206 } 207 208 /** Zoom **/ 209 210 /** 211 * @return The current zoom ratio. The min is 1.0f. 212 */ 213 public float getCurrentZoomRatio() { 214 return mCurrentZoomRatio; 215 } 216 217 /** 218 * Sets the zoom ratio. 219 * @param ratio The new zoom ratio. Should be in the range between 1.0 to 220 * the value returned from {@link 221 * com.android.camera.cameradevice.CameraCapabilities#getMaxZoomRatio()}. 222 * @throws java.lang.UnsupportedOperationException if the ratio is not 223 * supported. 224 */ 225 public void setZoomRatio(float ratio) { 226 mCurrentZoomRatio = ratio; 227 } 228 229 @Deprecated 230 public int getCurrentZoomIndex() { 231 return mCurrentZoomIndex; 232 } 233 234 @Deprecated 235 public void setZoomIndex(int index) { 236 mCurrentZoomIndex = index; 237 } 238 239 /** Transformation **/ 240 241 public void setPhotoRotationDegrees(float photoRotationDegrees) { 242 mPhotoRotationDegrees = photoRotationDegrees; 243 } 244 245 public float getCurrentPhotoRotationDegrees() { 246 return mPhotoRotationDegrees; 247 } 248 249 /** Exposure **/ 250 251 public void setExposureCompensationIndex(int index) { 252 mExposureCompensationIndex = index; 253 } 254 255 public int getExposureCompensationIndex() { 256 return mExposureCompensationIndex; 257 } 258 259 public void setAutoExposureLock(boolean locked) { 260 mAutoExposureLocked = locked; 261 } 262 263 public boolean isAutoExposureLocked() { 264 return mAutoExposureLocked; 265 } 266 267 public void setMeteringAreas(List<Camera.Area> areas) { 268 mMeteringAreas.clear(); 269 if (areas != null) { 270 mMeteringAreas.addAll(areas); 271 } 272 } 273 274 public List<Camera.Area> getMeteringAreas() { 275 return new ArrayList<Camera.Area>(mMeteringAreas); 276 } 277 278 /** Flash **/ 279 280 public CameraCapabilities.FlashMode getCurrentFlashMode() { 281 return mCurrentFlashMode; 282 } 283 284 public void setFlashMode(CameraCapabilities.FlashMode flashMode) { 285 mCurrentFlashMode = flashMode; 286 } 287 288 /** Focus **/ 289 290 /** 291 * Sets the focus mode. 292 * @param focusMode The focus mode to use. 293 */ 294 public void setFocusMode(CameraCapabilities.FocusMode focusMode) { 295 mCurrentFocusMode = focusMode; 296 } 297 298 /** 299 * @return The current focus mode. 300 */ 301 public CameraCapabilities.FocusMode getCurrentFocusMode() { 302 return mCurrentFocusMode; 303 } 304 305 /** 306 * @param areas The areas to focus. 307 */ 308 public void setFocusAreas(List<Camera.Area> areas) { 309 mFocusAreas.clear(); 310 if (areas != null) { 311 mFocusAreas.addAll(areas); 312 } 313 } 314 315 public List<Camera.Area> getFocusAreas() { 316 return new ArrayList<Camera.Area>(mFocusAreas); 317 } 318 319 /** White balance **/ 320 321 public void setWhiteBalance(CameraCapabilities.WhiteBalance whiteBalance) { 322 mWhiteBalance = whiteBalance; 323 } 324 325 public CameraCapabilities.WhiteBalance getWhiteBalance() { 326 return mWhiteBalance; 327 } 328 329 public void setAutoWhiteBalanceLock(boolean locked) { 330 mAutoWhiteBalanceLocked = locked; 331 } 332 333 public boolean isAutoWhiteBalanceLocked() { 334 return mAutoWhiteBalanceLocked; 335 } 336 337 /** Scene mode **/ 338 339 /** 340 * @return The current scene mode. 341 */ 342 public CameraCapabilities.SceneMode getCurrentSceneMode() { 343 return mCurrentSceneMode; 344 } 345 346 /** 347 * Sets the scene mode for capturing. 348 * 349 * @param sceneMode The scene mode to use. 350 * @throws java.lang.UnsupportedOperationException if it's not supported. 351 */ 352 public void setSceneMode(CameraCapabilities.SceneMode sceneMode) { 353 mCurrentSceneMode = sceneMode; 354 } 355 356 /** Other Features **/ 357 358 public void setVideoStabilization(boolean enabled) { 359 mVideoStabilizationEnabled = enabled; 360 } 361 362 public boolean isVideoStabilizationEnabled() { 363 return mVideoStabilizationEnabled; 364 } 365 366 public void setGpsData(GpsData data) { 367 mGpsData = new GpsData(data); 368 } 369 370 public GpsData getGpsData() { 371 return (mGpsData == null ? null : new GpsData(mGpsData)); 372 } 373 374 public void clearGpsData() { 375 mGpsData = null; 376 } 377} 378