mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-16 11:20:55 +01:00
commit
c568021e49
@ -43,7 +43,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||
|
||||
private var mPreview: MyPreview? = null
|
||||
private var mPreviewUri: Uri? = null
|
||||
private var mIsInPhotoMode = false
|
||||
private var mIsInPhotoMode = true
|
||||
private var mIsCameraAvailable = false
|
||||
private var mIsHardwareShutterHandled = false
|
||||
private var mCurrVideoRecTimer = 0
|
||||
@ -154,11 +154,23 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||
}
|
||||
|
||||
private fun tryInitCamera() {
|
||||
handlePermission(PERMISSION_CAMERA) {
|
||||
if (it) {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
||||
if (it) {
|
||||
initializeCamera()
|
||||
handlePermission(PERMISSION_CAMERA) { grantedCameraPermission ->
|
||||
if (grantedCameraPermission) {
|
||||
handlePermission(PERMISSION_WRITE_STORAGE) { grantedStoragePermission ->
|
||||
if (grantedStoragePermission) {
|
||||
if (mIsInPhotoMode) {
|
||||
initializeCamera()
|
||||
} else {
|
||||
handlePermission(PERMISSION_RECORD_AUDIO) { grantedRecordAudioPermission ->
|
||||
if (grantedRecordAudioPermission) {
|
||||
initializeCamera()
|
||||
} else {
|
||||
toast(R.string.no_audio_permissions)
|
||||
togglePhotoVideoMode()
|
||||
tryInitCamera()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast(R.string.no_storage_permissions)
|
||||
finish()
|
||||
@ -325,12 +337,16 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||
|
||||
mPreview?.setFlashlightState(FLASH_OFF)
|
||||
hideTimer()
|
||||
mIsInPhotoMode = !mIsInPhotoMode
|
||||
config.initPhotoMode = mIsInPhotoMode
|
||||
togglePhotoVideoMode()
|
||||
checkButtons()
|
||||
toggleBottomButtons(false)
|
||||
}
|
||||
|
||||
private fun togglePhotoVideoMode() {
|
||||
mIsInPhotoMode = !mIsInPhotoMode
|
||||
config.initPhotoMode = mIsInPhotoMode
|
||||
}
|
||||
|
||||
private fun checkButtons() {
|
||||
if (mIsInPhotoMode) {
|
||||
initPhotoMode()
|
||||
@ -456,7 +472,13 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasStorageAndCameraPermissions() = hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
|
||||
private fun hasStorageAndCameraPermissions(): Boolean {
|
||||
return if (mIsInPhotoMode) {
|
||||
hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
|
||||
} else {
|
||||
hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA) && hasPermission(PERMISSION_RECORD_AUDIO)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupOrientationEventListener() {
|
||||
mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.simplemobiletools.camera.helpers
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.simplemobiletools.commons.extensions.removeValues
|
||||
import java.io.IOException
|
||||
|
||||
class ExifRemover(private val contentResolver: ContentResolver) {
|
||||
companion object {
|
||||
private const val MODE = "rw"
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun removeExif(uri: Uri) {
|
||||
try {
|
||||
val fileDescriptor = contentResolver.openFileDescriptor(uri, MODE)
|
||||
if (fileDescriptor != null) {
|
||||
val exifInterface = ExifInterface(fileDescriptor.fileDescriptor)
|
||||
exifInterface.removeValues()
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ import com.simplemobiletools.camera.helpers.*
|
||||
import com.simplemobiletools.camera.interfaces.MyPreview
|
||||
import com.simplemobiletools.camera.models.MediaOutput
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
@ -58,6 +59,7 @@ class CameraXPreview(
|
||||
private val windowMetricsCalculator = WindowMetricsCalculator.getOrCreate()
|
||||
private val videoQualityManager = VideoQualityManager(config)
|
||||
private val imageQualityManager = ImageQualityManager(activity)
|
||||
private val exifRemover = ExifRemover(contentResolver)
|
||||
|
||||
private val orientationEventListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||
@SuppressLint("RestrictedApi")
|
||||
@ -368,8 +370,17 @@ class CameraXPreview(
|
||||
|
||||
imageCapture.takePicture(outputOptions, mainExecutor, object : OnImageSavedCallback {
|
||||
override fun onImageSaved(outputFileResults: OutputFileResults) {
|
||||
listener.toggleBottomButtons(false)
|
||||
listener.onMediaSaved(mediaOutput.uri ?: outputFileResults.savedUri!!)
|
||||
ensureBackgroundThread {
|
||||
val savedUri = mediaOutput.uri ?: outputFileResults.savedUri!!
|
||||
if (!config.savePhotoMetadata) {
|
||||
exifRemover.removeExif(savedUri)
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
listener.toggleBottomButtons(false)
|
||||
listener.onMediaSaved(savedUri)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(exception: ImageCaptureException) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user