mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-18 20:30:38 +01:00
do some preparations for target SDK 29
This commit is contained in:
parent
d233671c95
commit
51c55811d6
@ -17,7 +17,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString()
|
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString()
|
||||||
savePhotosFolder = path
|
savePhotosFolder = path
|
||||||
}
|
}
|
||||||
return path
|
return path!!
|
||||||
}
|
}
|
||||||
set(path) = prefs.edit().putString(SAVE_PHOTOS, path).apply()
|
set(path) = prefs.edit().putString(SAVE_PHOTOS, path).apply()
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
|
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
|
||||||
|
|
||||||
var lastUsedCamera: String
|
var lastUsedCamera: String
|
||||||
get() = prefs.getString(LAST_USED_CAMERA, "0")
|
get() = prefs.getString(LAST_USED_CAMERA, "0")!!
|
||||||
set(cameraId) = prefs.edit().putString(LAST_USED_CAMERA, cameraId).apply()
|
set(cameraId) = prefs.edit().putString(LAST_USED_CAMERA, cameraId).apply()
|
||||||
|
|
||||||
var initPhotoMode: Boolean
|
var initPhotoMode: Boolean
|
||||||
|
@ -30,7 +30,7 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
|
|||||||
val path: String
|
val path: String
|
||||||
try {
|
try {
|
||||||
path = if (saveUri != null) {
|
path = if (saveUri != null) {
|
||||||
saveUri.path
|
saveUri.path!!
|
||||||
} else {
|
} else {
|
||||||
activity.getOutputMediaFile(true)
|
activity.getOutputMediaFile(true)
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
|
|||||||
val documentFile = activity.getSomeDocumentFile(path)
|
val documentFile = activity.getSomeDocumentFile(path)
|
||||||
if (documentFile != null) {
|
if (documentFile != null) {
|
||||||
val parcelFileDescriptor = activity.contentResolver.openFileDescriptor(documentFile.uri, "rw")
|
val parcelFileDescriptor = activity.contentResolver.openFileDescriptor(documentFile.uri, "rw")
|
||||||
val fileDescriptor = parcelFileDescriptor.fileDescriptor
|
val fileDescriptor = parcelFileDescriptor!!.fileDescriptor
|
||||||
ExifInterface(fileDescriptor)
|
ExifInterface(fileDescriptor)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
@ -239,8 +239,8 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleZoom(event: MotionEvent) {
|
private fun handleZoom(event: MotionEvent) {
|
||||||
val maxZoom = getCameraCharacteristics().get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) * 10
|
val maxZoom = getCameraCharacteristics().get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM)!! * 10
|
||||||
val sensorRect = getCameraCharacteristics(mCameraId).get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
|
val sensorRect = getCameraCharacteristics(mCameraId).get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)!!
|
||||||
val currentFingerSpacing = getFingerSpacing(event)
|
val currentFingerSpacing = getFingerSpacing(event)
|
||||||
if (mZoomFingerSpacing != 0f) {
|
if (mZoomFingerSpacing != 0f) {
|
||||||
if (currentFingerSpacing > mZoomFingerSpacing && maxZoom > mZoomLevel) {
|
if (currentFingerSpacing > mZoomFingerSpacing && maxZoom > mZoomLevel) {
|
||||||
@ -260,7 +260,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
mZoomRect = Rect(cropWidth, cropHeight, sensorRect.width() - cropWidth, sensorRect.height() - cropHeight)
|
mZoomRect = Rect(cropWidth, cropHeight, sensorRect.width() - cropWidth, sensorRect.height() - cropHeight)
|
||||||
mPreviewRequestBuilder!!.set(CaptureRequest.SCALER_CROP_REGION, mZoomRect)
|
mPreviewRequestBuilder!!.set(CaptureRequest.SCALER_CROP_REGION, mZoomRect)
|
||||||
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequest!!, mCaptureCallback, mBackgroundHandler)
|
||||||
}
|
}
|
||||||
mZoomFingerSpacing = currentFingerSpacing
|
mZoomFingerSpacing = currentFingerSpacing
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentResolution(): MySize {
|
private fun getCurrentResolution(): MySize {
|
||||||
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
|
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
|
||||||
val resIndex = if (mUseFrontCamera) {
|
val resIndex = if (mUseFrontCamera) {
|
||||||
if (mIsInVideoMode) {
|
if (mIsInVideoMode) {
|
||||||
mActivity.config.frontVideoResIndex
|
mActivity.config.frontVideoResIndex
|
||||||
@ -322,7 +322,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
|
|
||||||
mCameraId = cameraId
|
mCameraId = cameraId
|
||||||
mActivity.config.lastUsedCamera = mCameraId
|
mActivity.config.lastUsedCamera = mCameraId
|
||||||
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
|
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
|
||||||
val currentResolution = getCurrentResolution()
|
val currentResolution = getCurrentResolution()
|
||||||
|
|
||||||
if (mIsInVideoMode) {
|
if (mIsInVideoMode) {
|
||||||
@ -372,7 +372,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
characteristics.apply {
|
characteristics.apply {
|
||||||
mIsFlashSupported = get(CameraCharacteristics.FLASH_INFO_AVAILABLE) ?: false
|
mIsFlashSupported = get(CameraCharacteristics.FLASH_INFO_AVAILABLE) ?: false
|
||||||
mIsZoomSupported = get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) ?: 0f > 0f
|
mIsZoomSupported = get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) ?: 0f > 0f
|
||||||
mIsFocusSupported = get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES).size > 1
|
mIsFocusSupported = get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES)!!.size > 1
|
||||||
}
|
}
|
||||||
mActivity.setFlashAvailable(mIsFlashSupported)
|
mActivity.setFlashAvailable(mIsFlashSupported)
|
||||||
mActivity.updateCameraIcon(mUseFrontCamera)
|
mActivity.updateCameraIcon(mUseFrontCamera)
|
||||||
@ -465,7 +465,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
setFlashAndExposure(this)
|
setFlashAndExposure(this)
|
||||||
mPreviewRequest = build()
|
mPreviewRequest = build()
|
||||||
}
|
}
|
||||||
mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession!!.setRepeatingRequest(mPreviewRequest!!, mCaptureCallback, mBackgroundHandler)
|
||||||
}
|
}
|
||||||
mCameraState = STATE_PREVIEW
|
mCameraState = STATE_PREVIEW
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -495,7 +495,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFrameRange(): Range<Int> {
|
private fun getFrameRange(): Range<Int> {
|
||||||
val ranges = getCameraCharacteristics().get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)
|
val ranges = getCameraCharacteristics().get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)!!
|
||||||
var currRangeSize = -1
|
var currRangeSize = -1
|
||||||
var currMinRange = 0
|
var currMinRange = 0
|
||||||
var result: Range<Int>? = null
|
var result: Range<Int>? = null
|
||||||
@ -599,7 +599,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
mActivity.toggleBottomButtons(false)
|
mActivity.toggleBottomButtons(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCaptureFailed(session: CameraCaptureSession?, request: CaptureRequest?, failure: CaptureFailure?) {
|
override fun onCaptureFailed(session: CameraCaptureSession, request: CaptureRequest, failure: CaptureFailure) {
|
||||||
super.onCaptureFailed(session, request, failure)
|
super.onCaptureFailed(session, request, failure)
|
||||||
mActivity.toggleBottomButtons(false)
|
mActivity.toggleBottomButtons(false)
|
||||||
}
|
}
|
||||||
@ -640,9 +640,9 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
|
|
||||||
// touch-to-focus inspired by OpenCamera
|
// touch-to-focus inspired by OpenCamera
|
||||||
val characteristics = getCameraCharacteristics()
|
val characteristics = getCameraCharacteristics()
|
||||||
if (characteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF) >= 1) {
|
if (characteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF)!! >= 1) {
|
||||||
val focusArea = getFocusArea(x, y)
|
val focusArea = getFocusArea(x, y)
|
||||||
val sensorRect = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
|
val sensorRect = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)!!
|
||||||
val meteringRect = convertAreaToMeteringRectangle(sensorRect, focusArea)
|
val meteringRect = convertAreaToMeteringRectangle(sensorRect, focusArea)
|
||||||
set(CaptureRequest.CONTROL_AF_REGIONS, arrayOf(meteringRect))
|
set(CaptureRequest.CONTROL_AF_REGIONS, arrayOf(meteringRect))
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
mCaptureSession?.capture(build(), mCaptureCallback, mBackgroundHandler)
|
mCaptureSession?.capture(build(), mCaptureCallback, mBackgroundHandler)
|
||||||
}
|
}
|
||||||
mCameraState = STATE_PREVIEW
|
mCameraState = STATE_PREVIEW
|
||||||
mCaptureSession?.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession?.setRepeatingRequest(mPreviewRequest!!, mCaptureCallback, mBackgroundHandler)
|
||||||
|
|
||||||
if (mLastFocusX != 0f && mLastFocusY != 0f) {
|
if (mLastFocusX != 0f && mLastFocusY != 0f) {
|
||||||
focusArea(mLastFocusX, mLastFocusY, false)
|
focusArea(mLastFocusX, mLastFocusY, false)
|
||||||
@ -784,7 +784,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
Uri.fromFile(File(mLastVideoPath))
|
Uri.fromFile(File(mLastVideoPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
val fileDescriptor = context.contentResolver.openFileDescriptor(uri, "w").fileDescriptor
|
val fileDescriptor = context.contentResolver.openFileDescriptor(uri, "w")!!.fileDescriptor
|
||||||
|
|
||||||
val rotation = mActivity.windowManager.defaultDisplay.rotation
|
val rotation = mActivity.windowManager.defaultDisplay.rotation
|
||||||
mMediaRecorder!!.apply {
|
mMediaRecorder!!.apply {
|
||||||
@ -839,7 +839,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val captureCallback = object : CameraCaptureSession.StateCallback() {
|
val captureCallback = object : CameraCaptureSession.StateCallback() {
|
||||||
override fun onConfigured(session: CameraCaptureSession?) {
|
override fun onConfigured(session: CameraCaptureSession) {
|
||||||
mCaptureSession = session
|
mCaptureSession = session
|
||||||
updatePreview()
|
updatePreview()
|
||||||
mIsRecording = true
|
mIsRecording = true
|
||||||
@ -850,7 +850,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
mCameraState = STATE_RECORDING
|
mCameraState = STATE_RECORDING
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigureFailed(session: CameraCaptureSession?) {
|
override fun onConfigureFailed(session: CameraCaptureSession) {
|
||||||
mCameraState = STATE_PREVIEW
|
mCameraState = STATE_PREVIEW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -917,7 +917,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
|
|
||||||
private fun openResolutionsDialog(openVideoResolutions: Boolean) {
|
private fun openResolutionsDialog(openVideoResolutions: Boolean) {
|
||||||
val oldResolution = getCurrentResolution()
|
val oldResolution = getCurrentResolution()
|
||||||
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
|
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
|
||||||
val photoResolutions = configMap.getOutputSizes(ImageFormat.JPEG).map { MySize(it.width, it.height) } as ArrayList
|
val photoResolutions = configMap.getOutputSizes(ImageFormat.JPEG).map { MySize(it.width, it.height) } as ArrayList
|
||||||
val videoResolutions = getAvailableVideoSizes(configMap).map { MySize(it.width, it.height) } as ArrayList
|
val videoResolutions = getAvailableVideoSizes(configMap).map { MySize(it.width, it.height) } as ArrayList
|
||||||
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions, openVideoResolutions) {
|
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions, openVideoResolutions) {
|
||||||
@ -994,7 +994,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
try {
|
try {
|
||||||
setFlashAndExposure(mPreviewRequestBuilder!!)
|
setFlashAndExposure(mPreviewRequestBuilder!!)
|
||||||
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
mPreviewRequest = mPreviewRequestBuilder!!.build()
|
||||||
mCaptureSession?.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler)
|
mCaptureSession?.setRepeatingRequest(mPreviewRequest!!, mCaptureCallback, mBackgroundHandler)
|
||||||
mActivity.updateFlashlightState(mFlashlightState)
|
mActivity.updateFlashlightState(mFlashlightState)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user