mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-04-29 14:38:51 +02:00
commit
c568021e49
@ -43,7 +43,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
private var mPreview: MyPreview? = null
|
private var mPreview: MyPreview? = null
|
||||||
private var mPreviewUri: Uri? = null
|
private var mPreviewUri: Uri? = null
|
||||||
private var mIsInPhotoMode = false
|
private var mIsInPhotoMode = true
|
||||||
private var mIsCameraAvailable = false
|
private var mIsCameraAvailable = false
|
||||||
private var mIsHardwareShutterHandled = false
|
private var mIsHardwareShutterHandled = false
|
||||||
private var mCurrVideoRecTimer = 0
|
private var mCurrVideoRecTimer = 0
|
||||||
@ -154,11 +154,23 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun tryInitCamera() {
|
private fun tryInitCamera() {
|
||||||
handlePermission(PERMISSION_CAMERA) {
|
handlePermission(PERMISSION_CAMERA) { grantedCameraPermission ->
|
||||||
if (it) {
|
if (grantedCameraPermission) {
|
||||||
handlePermission(PERMISSION_WRITE_STORAGE) {
|
handlePermission(PERMISSION_WRITE_STORAGE) { grantedStoragePermission ->
|
||||||
if (it) {
|
if (grantedStoragePermission) {
|
||||||
|
if (mIsInPhotoMode) {
|
||||||
initializeCamera()
|
initializeCamera()
|
||||||
|
} else {
|
||||||
|
handlePermission(PERMISSION_RECORD_AUDIO) { grantedRecordAudioPermission ->
|
||||||
|
if (grantedRecordAudioPermission) {
|
||||||
|
initializeCamera()
|
||||||
|
} else {
|
||||||
|
toast(R.string.no_audio_permissions)
|
||||||
|
togglePhotoVideoMode()
|
||||||
|
tryInitCamera()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_storage_permissions)
|
toast(R.string.no_storage_permissions)
|
||||||
finish()
|
finish()
|
||||||
@ -325,12 +337,16 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
mPreview?.setFlashlightState(FLASH_OFF)
|
mPreview?.setFlashlightState(FLASH_OFF)
|
||||||
hideTimer()
|
hideTimer()
|
||||||
mIsInPhotoMode = !mIsInPhotoMode
|
togglePhotoVideoMode()
|
||||||
config.initPhotoMode = mIsInPhotoMode
|
|
||||||
checkButtons()
|
checkButtons()
|
||||||
toggleBottomButtons(false)
|
toggleBottomButtons(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun togglePhotoVideoMode() {
|
||||||
|
mIsInPhotoMode = !mIsInPhotoMode
|
||||||
|
config.initPhotoMode = mIsInPhotoMode
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkButtons() {
|
private fun checkButtons() {
|
||||||
if (mIsInPhotoMode) {
|
if (mIsInPhotoMode) {
|
||||||
initPhotoMode()
|
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() {
|
private fun setupOrientationEventListener() {
|
||||||
mOrientationEventListener = object : OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
|
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.interfaces.MyPreview
|
||||||
import com.simplemobiletools.camera.models.MediaOutput
|
import com.simplemobiletools.camera.models.MediaOutput
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -58,6 +59,7 @@ class CameraXPreview(
|
|||||||
private val windowMetricsCalculator = WindowMetricsCalculator.getOrCreate()
|
private val windowMetricsCalculator = WindowMetricsCalculator.getOrCreate()
|
||||||
private val videoQualityManager = VideoQualityManager(config)
|
private val videoQualityManager = VideoQualityManager(config)
|
||||||
private val imageQualityManager = ImageQualityManager(activity)
|
private val imageQualityManager = ImageQualityManager(activity)
|
||||||
|
private val exifRemover = ExifRemover(contentResolver)
|
||||||
|
|
||||||
private val orientationEventListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_NORMAL) {
|
private val orientationEventListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
@ -368,8 +370,17 @@ class CameraXPreview(
|
|||||||
|
|
||||||
imageCapture.takePicture(outputOptions, mainExecutor, object : OnImageSavedCallback {
|
imageCapture.takePicture(outputOptions, mainExecutor, object : OnImageSavedCallback {
|
||||||
override fun onImageSaved(outputFileResults: OutputFileResults) {
|
override fun onImageSaved(outputFileResults: OutputFileResults) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
val savedUri = mediaOutput.uri ?: outputFileResults.savedUri!!
|
||||||
|
if (!config.savePhotoMetadata) {
|
||||||
|
exifRemover.removeExif(savedUri)
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.runOnUiThread {
|
||||||
listener.toggleBottomButtons(false)
|
listener.toggleBottomButtons(false)
|
||||||
listener.onMediaSaved(mediaOutput.uri ?: outputFileResults.savedUri!!)
|
listener.onMediaSaved(savedUri)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(exception: ImageCaptureException) {
|
override fun onError(exception: ImageCaptureException) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user