mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
remove logs
This commit is contained in:
@ -9,7 +9,6 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
@ -33,7 +32,6 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|||||||
|
|
||||||
class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener {
|
class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "MainActivity"
|
|
||||||
private const val FADE_DELAY = 5000L
|
private const val FADE_DELAY = 5000L
|
||||||
private const val CAPTURE_ANIMATION_DURATION = 100L
|
private const val CAPTURE_ANIMATION_DURATION = 100L
|
||||||
}
|
}
|
||||||
@ -122,15 +120,12 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
private fun initVariables() {
|
private fun initVariables() {
|
||||||
mIsInPhotoMode = if (isVideoCaptureIntent()) {
|
mIsInPhotoMode = if (isVideoCaptureIntent()) {
|
||||||
Log.w(TAG, "initializeCamera: video capture")
|
|
||||||
false
|
false
|
||||||
} else if (isImageCaptureIntent()) {
|
} else if (isImageCaptureIntent()) {
|
||||||
Log.w(TAG, "initializeCamera: image capture mode")
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
config.initPhotoMode
|
config.initPhotoMode
|
||||||
}
|
}
|
||||||
Log.w(TAG, "initInPhotoMode = $mIsInPhotoMode")
|
|
||||||
mIsCameraAvailable = false
|
mIsCameraAvailable = false
|
||||||
mIsHardwareShutterHandled = false
|
mIsHardwareShutterHandled = false
|
||||||
mCurrVideoRecTimer = 0
|
mCurrVideoRecTimer = 0
|
||||||
@ -202,7 +197,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
private fun checkImageCaptureIntent() {
|
private fun checkImageCaptureIntent() {
|
||||||
if (isImageCaptureIntent()) {
|
if (isImageCaptureIntent()) {
|
||||||
Log.i(TAG, "isImageCaptureIntent: ")
|
|
||||||
hideIntentButtons()
|
hideIntentButtons()
|
||||||
val output = intent.extras?.get(MediaStore.EXTRA_OUTPUT)
|
val output = intent.extras?.get(MediaStore.EXTRA_OUTPUT)
|
||||||
if (output != null && output is Uri) {
|
if (output != null && output is Uri) {
|
||||||
@ -213,7 +207,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
private fun checkVideoCaptureIntent() {
|
private fun checkVideoCaptureIntent() {
|
||||||
if (intent?.action == MediaStore.ACTION_VIDEO_CAPTURE) {
|
if (intent?.action == MediaStore.ACTION_VIDEO_CAPTURE) {
|
||||||
Log.i(TAG, "checkVideoCaptureIntent: ")
|
|
||||||
mIsInPhotoMode = false
|
mIsInPhotoMode = false
|
||||||
hideIntentButtons()
|
hideIntentButtons()
|
||||||
shutter.setImageResource(R.drawable.ic_video_rec)
|
shutter.setImageResource(R.drawable.ic_video_rec)
|
||||||
@ -402,7 +395,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
mPreviewUri = Uri.withAppendedPath(uri, lastMediaId.toString())
|
mPreviewUri = Uri.withAppendedPath(uri, lastMediaId.toString())
|
||||||
|
|
||||||
Log.e(TAG, "mPreviewUri= $mPreviewUri")
|
|
||||||
|
|
||||||
loadLastTakenMedia(mPreviewUri)
|
loadLastTakenMedia(mPreviewUri)
|
||||||
}
|
}
|
||||||
@ -585,7 +577,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
setResult(Activity.RESULT_OK, this)
|
setResult(Activity.RESULT_OK, this)
|
||||||
}
|
}
|
||||||
Log.w(TAG, "onMediaCaptured: exiting uri=$uri")
|
|
||||||
finish()
|
finish()
|
||||||
} else if (isVideoCaptureIntent()) {
|
} else if (isVideoCaptureIntent()) {
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
@ -593,7 +584,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
setResult(Activity.RESULT_OK, this)
|
setResult(Activity.RESULT_OK, this)
|
||||||
}
|
}
|
||||||
Log.w(TAG, "onMediaCaptured: video exiting uri=$uri")
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -604,7 +594,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
putExtra("data", bitmap)
|
putExtra("data", bitmap)
|
||||||
setResult(Activity.RESULT_OK, this)
|
setResult(Activity.RESULT_OK, this)
|
||||||
}
|
}
|
||||||
Log.w(TAG, "onImageCaptured: exiting bitmap size=${bitmap.byteCount}")
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -663,7 +652,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y)
|
fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y)
|
||||||
|
|
||||||
override fun mediaSaved(path: String) {
|
override fun mediaSaved(path: String) {
|
||||||
Log.e(TAG, "mediaSaved: $path")
|
|
||||||
rescanPaths(arrayListOf(path)) {
|
rescanPaths(arrayListOf(path)) {
|
||||||
setupPreviewImage(true)
|
setupPreviewImage(true)
|
||||||
Intent(BROADCAST_REFRESH_MEDIA).apply {
|
Intent(BROADCAST_REFRESH_MEDIA).apply {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.simplemobiletools.camera.dialogs
|
package com.simplemobiletools.camera.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@ -28,7 +27,6 @@ class ChangeResolutionDialogX(
|
|||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
private val config = activity.config
|
private val config = activity.config
|
||||||
|
|
||||||
private val TAG = "ChangeResolutionDialogX"
|
|
||||||
init {
|
init {
|
||||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
|
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
|
||||||
setupPhotoResolutionPicker(this)
|
setupPhotoResolutionPicker(this)
|
||||||
@ -57,7 +55,6 @@ class ChangeResolutionDialogX(
|
|||||||
view.change_resolution_photo_holder.setOnClickListener {
|
view.change_resolution_photo_holder.setOnClickListener {
|
||||||
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
|
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
|
||||||
selectionIndex = it as Int
|
selectionIndex = it as Int
|
||||||
Log.w(TAG, "setupPhotoResolutionPicker: selectionIndex=$it")
|
|
||||||
view.change_resolution_photo.text = items[selectionIndex].title
|
view.change_resolution_photo.text = items[selectionIndex].title
|
||||||
if (isFrontCamera) {
|
if (isFrontCamera) {
|
||||||
config.frontPhotoResIndex = it
|
config.frontPhotoResIndex = it
|
||||||
@ -80,8 +77,6 @@ class ChangeResolutionDialogX(
|
|||||||
|
|
||||||
var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex
|
var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex
|
||||||
selectionIndex = selectionIndex.coerceAtLeast(0)
|
selectionIndex = selectionIndex.coerceAtLeast(0)
|
||||||
Log.i(TAG, "videoResolutions=$videoResolutions")
|
|
||||||
Log.i(TAG, "setupVideoResolutionPicker: selectionIndex=$selectionIndex")
|
|
||||||
|
|
||||||
view.change_resolution_video_holder.setOnClickListener {
|
view.change_resolution_video_holder.setOnClickListener {
|
||||||
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
|
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
|
||||||
@ -99,6 +94,5 @@ class ChangeResolutionDialogX(
|
|||||||
}
|
}
|
||||||
val selectedItem = items.getOrNull(selectionIndex)
|
val selectedItem = items.getOrNull(selectionIndex)
|
||||||
view.change_resolution_video.text = selectedItem?.title
|
view.change_resolution_video.text = selectedItem?.title
|
||||||
Log.i(TAG, "setupVideoResolutionPicker: selectedItem=$selectedItem")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@ package com.simplemobiletools.camera.helpers
|
|||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.util.Log
|
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
//inspired by https://android.googlesource.com/platform/packages/apps/Camera2/+/refs/heads/master/src/com/android/camera/util/CameraUtil.java#244
|
//inspired by https://android.googlesource.com/platform/packages/apps/Camera2/+/refs/heads/master/src/com/android/camera/util/CameraUtil.java#244
|
||||||
object BitmapUtils {
|
object BitmapUtils {
|
||||||
private const val TAG = "BitmapUtils"
|
|
||||||
private const val INLINE_BITMAP_MAX_PIXEL_NUM = 50 * 1024
|
private const val INLINE_BITMAP_MAX_PIXEL_NUM = 50 * 1024
|
||||||
|
|
||||||
fun makeBitmap(jpegData: ByteArray, maxNumOfPixels: Int = INLINE_BITMAP_MAX_PIXEL_NUM): Bitmap? {
|
fun makeBitmap(jpegData: ByteArray, maxNumOfPixels: Int = INLINE_BITMAP_MAX_PIXEL_NUM): Bitmap? {
|
||||||
@ -31,7 +29,6 @@ object BitmapUtils {
|
|||||||
options
|
options
|
||||||
)
|
)
|
||||||
} catch (ex: OutOfMemoryError) {
|
} catch (ex: OutOfMemoryError) {
|
||||||
Log.e(TAG, "Got oom exception ", ex)
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,19 @@ import android.hardware.camera2.CameraCharacteristics
|
|||||||
import android.hardware.camera2.CameraManager
|
import android.hardware.camera2.CameraManager
|
||||||
import android.hardware.camera2.params.StreamConfigurationMap
|
import android.hardware.camera2.params.StreamConfigurationMap
|
||||||
import android.media.MediaRecorder
|
import android.media.MediaRecorder
|
||||||
import android.util.Log
|
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.camera.core.CameraSelector
|
import androidx.camera.core.CameraSelector
|
||||||
import com.simplemobiletools.camera.extensions.config
|
import com.simplemobiletools.camera.extensions.config
|
||||||
import com.simplemobiletools.camera.models.CameraSelectorImageQualities
|
import com.simplemobiletools.camera.models.CameraSelectorImageQualities
|
||||||
import com.simplemobiletools.camera.models.MySize
|
import com.simplemobiletools.camera.models.MySize
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
|
|
||||||
class ImageQualityManager(
|
class ImageQualityManager(
|
||||||
activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "ImageQualityManager"
|
|
||||||
private const val MAX_VIDEO_WIDTH = 4096
|
private const val MAX_VIDEO_WIDTH = 4096
|
||||||
private const val MAX_VIDEO_HEIGHT = 2160
|
private const val MAX_VIDEO_HEIGHT = 2160
|
||||||
private val CAMERA_LENS = arrayOf(CameraCharacteristics.LENS_FACING_FRONT, CameraCharacteristics.LENS_FACING_BACK)
|
private val CAMERA_LENS = arrayOf(CameraCharacteristics.LENS_FACING_FRONT, CameraCharacteristics.LENS_FACING_BACK)
|
||||||
@ -39,11 +38,10 @@ class ImageQualityManager(
|
|||||||
val imageSizes = configMap.getOutputSizes(ImageFormat.JPEG).map { MySize(it.width, it.height) }
|
val imageSizes = configMap.getOutputSizes(ImageFormat.JPEG).map { MySize(it.width, it.height) }
|
||||||
val cameraSelector = lens.toCameraSelector()
|
val cameraSelector = lens.toCameraSelector()
|
||||||
imageQualities.add(CameraSelectorImageQualities(cameraSelector, imageSizes))
|
imageQualities.add(CameraSelectorImageQualities(cameraSelector, imageSizes))
|
||||||
Log.i(TAG, "initQualities: imageSizes=$imageSizes")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Camera ID=$cameraId is not supported", e)
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,12 +67,7 @@ class ImageQualityManager(
|
|||||||
.sortedByDescending { it.pixels }
|
.sortedByDescending { it.pixels }
|
||||||
.distinctBy { it.pixels }
|
.distinctBy { it.pixels }
|
||||||
.map { Size(it.width, it.height) }
|
.map { Size(it.width, it.height) }
|
||||||
.also {
|
.getOrNull(index)
|
||||||
Log.i(TAG, "Resolutions: $it, index=$index")
|
|
||||||
}
|
|
||||||
.getOrNull(index).also {
|
|
||||||
Log.i(TAG, "getUserSelectedResolution: $it, index=$index")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSupportedResolutions(cameraSelector: CameraSelector): List<MySize> {
|
fun getSupportedResolutions(cameraSelector: CameraSelector): List<MySize> {
|
||||||
|
@ -5,7 +5,6 @@ import android.net.Uri
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
|
||||||
import com.simplemobiletools.camera.extensions.config
|
import com.simplemobiletools.camera.extensions.config
|
||||||
import com.simplemobiletools.camera.extensions.getOutputMediaFile
|
import com.simplemobiletools.camera.extensions.getOutputMediaFile
|
||||||
import com.simplemobiletools.camera.extensions.getRandomMediaName
|
import com.simplemobiletools.camera.extensions.getRandomMediaName
|
||||||
@ -25,7 +24,6 @@ class MediaOutputHelper(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "MediaOutputHelper"
|
|
||||||
private const val MODE = "rw"
|
private const val MODE = "rw"
|
||||||
private const val EXTERNAL_VOLUME = "external"
|
private const val EXTERNAL_VOLUME = "external"
|
||||||
private const val IMAGE_MIME_TYPE = "image/jpeg"
|
private const val IMAGE_MIME_TYPE = "image/jpeg"
|
||||||
@ -112,7 +110,6 @@ class MediaOutputHelper(
|
|||||||
private fun getOutputStreamMediaOutput(): MediaOutput.OutputStreamMediaOutput? {
|
private fun getOutputStreamMediaOutput(): MediaOutput.OutputStreamMediaOutput? {
|
||||||
var mediaOutput: MediaOutput.OutputStreamMediaOutput? = null
|
var mediaOutput: MediaOutput.OutputStreamMediaOutput? = null
|
||||||
val canWrite = canWriteToFilePath(mediaStorageDir)
|
val canWrite = canWriteToFilePath(mediaStorageDir)
|
||||||
Log.i(TAG, "getMediaOutput: canWrite=${canWrite}")
|
|
||||||
if (canWrite) {
|
if (canWrite) {
|
||||||
val path = activity.getOutputMediaFile(true)
|
val path = activity.getOutputMediaFile(true)
|
||||||
val uri = getUriForFilePath(path)
|
val uri = getUriForFilePath(path)
|
||||||
@ -121,16 +118,14 @@ class MediaOutputHelper(
|
|||||||
mediaOutput = MediaOutput.OutputStreamMediaOutput(outputStream, uri)
|
mediaOutput = MediaOutput.OutputStreamMediaOutput(outputStream, uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i(TAG, "OutputStreamMediaOutput: $mediaOutput")
|
|
||||||
return mediaOutput
|
return mediaOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openOutputStream(uri: Uri): OutputStream? {
|
private fun openOutputStream(uri: Uri): OutputStream? {
|
||||||
return try {
|
return try {
|
||||||
Log.i(TAG, "uri: $uri")
|
|
||||||
contentResolver.openOutputStream(uri)
|
contentResolver.openOutputStream(uri)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
activity.showErrorToast(e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +133,6 @@ class MediaOutputHelper(
|
|||||||
private fun getFileDescriptorMediaOutput(): MediaOutput.FileDescriptorMediaOutput? {
|
private fun getFileDescriptorMediaOutput(): MediaOutput.FileDescriptorMediaOutput? {
|
||||||
var mediaOutput: MediaOutput.FileDescriptorMediaOutput? = null
|
var mediaOutput: MediaOutput.FileDescriptorMediaOutput? = null
|
||||||
val canWrite = canWriteToFilePath(mediaStorageDir)
|
val canWrite = canWriteToFilePath(mediaStorageDir)
|
||||||
Log.i(TAG, "getMediaOutput: canWrite=${canWrite}")
|
|
||||||
if (canWrite) {
|
if (canWrite) {
|
||||||
val path = activity.getOutputMediaFile(false)
|
val path = activity.getOutputMediaFile(false)
|
||||||
val uri = getUriForFilePath(path)
|
val uri = getUriForFilePath(path)
|
||||||
@ -149,14 +143,12 @@ class MediaOutputHelper(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i(TAG, "FileDescriptorMediaOutput: $mediaOutput")
|
|
||||||
return mediaOutput
|
return mediaOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFileMediaOutput(): MediaOutput.FileMediaOutput? {
|
private fun getFileMediaOutput(): MediaOutput.FileMediaOutput? {
|
||||||
var mediaOutput: MediaOutput.FileMediaOutput? = null
|
var mediaOutput: MediaOutput.FileMediaOutput? = null
|
||||||
val canWrite = canWriteToFilePath(mediaStorageDir)
|
val canWrite = canWriteToFilePath(mediaStorageDir)
|
||||||
Log.i(TAG, "getMediaOutput: canWrite=${canWrite}")
|
|
||||||
if (canWrite) {
|
if (canWrite) {
|
||||||
val path = activity.getOutputMediaFile(false)
|
val path = activity.getOutputMediaFile(false)
|
||||||
val uri = getUriForFilePath(path)
|
val uri = getUriForFilePath(path)
|
||||||
@ -164,16 +156,14 @@ class MediaOutputHelper(
|
|||||||
mediaOutput = MediaOutput.FileMediaOutput(File(path), uri)
|
mediaOutput = MediaOutput.FileMediaOutput(File(path), uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.i(TAG, "FileDescriptorMediaOutput: $mediaOutput")
|
|
||||||
return mediaOutput
|
return mediaOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openFileDescriptor(uri: Uri): ParcelFileDescriptor? {
|
private fun openFileDescriptor(uri: Uri): ParcelFileDescriptor? {
|
||||||
return try {
|
return try {
|
||||||
Log.i(TAG, "uri: $uri")
|
|
||||||
contentResolver.openFileDescriptor(uri, MODE)
|
contentResolver.openFileDescriptor(uri, MODE)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
activity.showErrorToast(e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +205,6 @@ class MediaOutputHelper(
|
|||||||
documentFile.createFile(path.getMimeType(), path.getFilenameFromPath())?.uri
|
documentFile.createFile(path.getMimeType(), path.getFilenameFromPath())?.uri
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,7 +213,6 @@ class MediaOutputHelper(
|
|||||||
try {
|
try {
|
||||||
activity.createDocumentUriUsingFirstParentTreeUri(path)
|
activity.createDocumentUriUsingFirstParentTreeUri(path)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
|
||||||
null
|
null
|
||||||
} ?: Uri.fromFile(targetFile)
|
} ?: Uri.fromFile(targetFile)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.simplemobiletools.camera.helpers
|
package com.simplemobiletools.camera.helpers
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.camera.core.CameraSelector
|
import androidx.camera.core.CameraSelector
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
@ -11,13 +10,13 @@ import com.simplemobiletools.camera.extensions.toCameraXQuality
|
|||||||
import com.simplemobiletools.camera.extensions.toVideoQuality
|
import com.simplemobiletools.camera.extensions.toVideoQuality
|
||||||
import com.simplemobiletools.camera.models.CameraSelectorVideoQualities
|
import com.simplemobiletools.camera.models.CameraSelectorVideoQualities
|
||||||
import com.simplemobiletools.camera.models.VideoQuality
|
import com.simplemobiletools.camera.models.VideoQuality
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
|
|
||||||
class VideoQualityManager(
|
class VideoQualityManager(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "VideoQualityHelper"
|
|
||||||
private val QUALITIES = listOf(Quality.UHD, Quality.FHD, Quality.HD, Quality.SD)
|
private val QUALITIES = listOf(Quality.UHD, Quality.FHD, Quality.HD, Quality.SD)
|
||||||
private val CAMERA_SELECTORS = arrayOf(CameraSelector.DEFAULT_BACK_CAMERA, CameraSelector.DEFAULT_FRONT_CAMERA)
|
private val CAMERA_SELECTORS = arrayOf(CameraSelector.DEFAULT_BACK_CAMERA, CameraSelector.DEFAULT_FRONT_CAMERA)
|
||||||
}
|
}
|
||||||
@ -37,12 +36,10 @@ class VideoQualityManager(
|
|||||||
.also { allQualities ->
|
.also { allQualities ->
|
||||||
val qualities = allQualities.map { it.toVideoQuality() }
|
val qualities = allQualities.map { it.toVideoQuality() }
|
||||||
videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities))
|
videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities))
|
||||||
|
|
||||||
}
|
}
|
||||||
Log.i(TAG, "bindCameraUseCases: videoQualities=$videoQualities")
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Camera Face $camSelector is not supported", e)
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.SensorManager
|
import android.hardware.SensorManager
|
||||||
import android.hardware.display.DisplayManager
|
import android.hardware.display.DisplayManager
|
||||||
import android.util.Log
|
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.view.GestureDetector.SimpleOnGestureListener
|
import android.view.GestureDetector.SimpleOnGestureListener
|
||||||
@ -43,7 +42,6 @@ class CameraXPreview(
|
|||||||
) : MyPreview, DefaultLifecycleObserver {
|
) : MyPreview, DefaultLifecycleObserver {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "CameraXPreview"
|
|
||||||
private const val RATIO_4_3_VALUE = 4.0 / 3.0
|
private const val RATIO_4_3_VALUE = 4.0 / 3.0
|
||||||
private const val RATIO_16_9_VALUE = 16.0 / 9.0
|
private const val RATIO_16_9_VALUE = 16.0 / 9.0
|
||||||
|
|
||||||
@ -75,7 +73,6 @@ class CameraXPreview(
|
|||||||
in 225 until 315 -> Surface.ROTATION_90
|
in 225 until 315 -> Surface.ROTATION_90
|
||||||
else -> Surface.ROTATION_0
|
else -> Surface.ROTATION_0
|
||||||
}
|
}
|
||||||
Log.i(TAG, "onOrientationChanged: rotation=$rotation")
|
|
||||||
preview?.targetRotation = rotation
|
preview?.targetRotation = rotation
|
||||||
imageCapture?.targetRotation = rotation
|
imageCapture?.targetRotation = rotation
|
||||||
videoCapture?.targetRotation = rotation
|
videoCapture?.targetRotation = rotation
|
||||||
@ -91,9 +88,7 @@ class CameraXPreview(
|
|||||||
private var recordingState: VideoRecordEvent? = null
|
private var recordingState: VideoRecordEvent? = null
|
||||||
private var cameraSelector = config.lastUsedCameraLens.toCameraSelector()
|
private var cameraSelector = config.lastUsedCameraLens.toCameraSelector()
|
||||||
private var flashMode = FLASH_MODE_OFF
|
private var flashMode = FLASH_MODE_OFF
|
||||||
private var isPhotoCapture = initInPhotoMode.also {
|
private var isPhotoCapture = initInPhotoMode
|
||||||
Log.i(TAG, "initInPhotoMode= $it")
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
bindToLifeCycle()
|
bindToLifeCycle()
|
||||||
@ -108,7 +103,6 @@ class CameraXPreview(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startCamera(switching: Boolean = false) {
|
private fun startCamera(switching: Boolean = false) {
|
||||||
Log.i(TAG, "startCamera: ")
|
|
||||||
imageQualityManager.initSupportedQualities()
|
imageQualityManager.initSupportedQualities()
|
||||||
|
|
||||||
val cameraProviderFuture = ProcessCameraProvider.getInstance(activity)
|
val cameraProviderFuture = ProcessCameraProvider.getInstance(activity)
|
||||||
@ -120,7 +114,6 @@ class CameraXPreview(
|
|||||||
bindCameraUseCases()
|
bindCameraUseCases()
|
||||||
setupCameraObservers()
|
setupCameraObservers()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "startCamera: ", e)
|
|
||||||
val errorMessage = if (switching) R.string.camera_switch_error else R.string.camera_open_error
|
val errorMessage = if (switching) R.string.camera_switch_error else R.string.camera_open_error
|
||||||
activity.toast(errorMessage)
|
activity.toast(errorMessage)
|
||||||
}
|
}
|
||||||
@ -197,9 +190,6 @@ class CameraXPreview(
|
|||||||
.apply {
|
.apply {
|
||||||
imageQualityManager.getUserSelectedResolution(cameraSelector)?.let { resolution ->
|
imageQualityManager.getUserSelectedResolution(cameraSelector)?.let { resolution ->
|
||||||
val rotatedResolution = getRotatedResolution(rotation, resolution)
|
val rotatedResolution = getRotatedResolution(rotation, resolution)
|
||||||
Log.i(TAG, "buildImageCapture: rotation=$rotation")
|
|
||||||
Log.i(TAG, "buildImageCapture: resolution=$resolution")
|
|
||||||
Log.i(TAG, "buildImageCapture: rotatedResolution=$rotatedResolution")
|
|
||||||
setTargetResolution(rotatedResolution)
|
setTargetResolution(rotatedResolution)
|
||||||
} ?: setTargetAspectRatio(aspectRatio)
|
} ?: setTargetAspectRatio(aspectRatio)
|
||||||
}
|
}
|
||||||
@ -255,7 +245,6 @@ class CameraXPreview(
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
// source: https://stackoverflow.com/a/60095886/10552591
|
// source: https://stackoverflow.com/a/60095886/10552591
|
||||||
private fun setupZoomAndFocus() {
|
private fun setupZoomAndFocus() {
|
||||||
Log.i(TAG, "camera controller: ${previewView.controller}")
|
|
||||||
val scaleGesture = camera?.let { ScaleGestureDetector(activity, PinchToZoomOnScaleGestureListener(it.cameraInfo, it.cameraControl)) }
|
val scaleGesture = camera?.let { ScaleGestureDetector(activity, PinchToZoomOnScaleGestureListener(it.cameraInfo, it.cameraControl)) }
|
||||||
val gestureDetector = GestureDetector(activity, object : SimpleOnGestureListener() {
|
val gestureDetector = GestureDetector(activity, object : SimpleOnGestureListener() {
|
||||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
|
||||||
@ -263,7 +252,6 @@ class CameraXPreview(
|
|||||||
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
|
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
|
||||||
val width = previewView.width.toFloat()
|
val width = previewView.width.toFloat()
|
||||||
val height = previewView.height.toFloat()
|
val height = previewView.height.toFloat()
|
||||||
Log.i(TAG, "onSingleTapConfirmed: width=$width,height=$height")
|
|
||||||
val factory = DisplayOrientedMeteringPointFactory(display, it, width, height)
|
val factory = DisplayOrientedMeteringPointFactory(display, it, width, height)
|
||||||
val xPos = event.x
|
val xPos = event.x
|
||||||
val yPos = event.y
|
val yPos = event.y
|
||||||
@ -275,13 +263,11 @@ class CameraXPreview(
|
|||||||
.build()
|
.build()
|
||||||
camera?.cameraControl?.startFocusAndMetering(focusMeteringAction)
|
camera?.cameraControl?.startFocusAndMetering(focusMeteringAction)
|
||||||
listener.onFocusCamera(xPos, yPos)
|
listener.onFocusCamera(xPos, yPos)
|
||||||
Log.i(TAG, "start focus")
|
|
||||||
true
|
true
|
||||||
} ?: false
|
} ?: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
previewView.setOnTouchListener { _, event ->
|
previewView.setOnTouchListener { _, event ->
|
||||||
Log.i(TAG, "setOnTouchListener: x=${event.x}, y=${event.y}")
|
|
||||||
gestureDetector.onTouchEvent(event)
|
gestureDetector.onTouchEvent(event)
|
||||||
scaleGesture?.onTouchEvent(event)
|
scaleGesture?.onTouchEvent(event)
|
||||||
true
|
true
|
||||||
@ -405,7 +391,6 @@ class CameraXPreview(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleImageCaptureError(exception: ImageCaptureException) {
|
private fun handleImageCaptureError(exception: ImageCaptureException) {
|
||||||
Log.e(TAG, "Error", exception)
|
|
||||||
listener.toggleBottomButtons(false)
|
listener.toggleBottomButtons(false)
|
||||||
cameraErrorHandler.handleImageCaptureError(exception.imageCaptureError)
|
cameraErrorHandler.handleImageCaptureError(exception.imageCaptureError)
|
||||||
}
|
}
|
||||||
@ -421,13 +406,11 @@ class CameraXPreview(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toggleRecording() {
|
override fun toggleRecording() {
|
||||||
Log.d(TAG, "toggleRecording: currentRecording=$currentRecording, recordingState=$recordingState")
|
|
||||||
if (currentRecording == null || recordingState is VideoRecordEvent.Finalize) {
|
if (currentRecording == null || recordingState is VideoRecordEvent.Finalize) {
|
||||||
startRecording()
|
startRecording()
|
||||||
} else {
|
} else {
|
||||||
currentRecording?.stop()
|
currentRecording?.stop()
|
||||||
currentRecording = null
|
currentRecording = null
|
||||||
Log.d(TAG, "Recording stopped")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +437,6 @@ class CameraXPreview(
|
|||||||
|
|
||||||
currentRecording = recording.withAudioEnabled()
|
currentRecording = recording.withAudioEnabled()
|
||||||
.start(mainExecutor) { recordEvent ->
|
.start(mainExecutor) { recordEvent ->
|
||||||
Log.d(TAG, "recordEvent=$recordEvent ")
|
|
||||||
recordingState = recordEvent
|
recordingState = recordEvent
|
||||||
when (recordEvent) {
|
when (recordEvent) {
|
||||||
is VideoRecordEvent.Start -> {
|
is VideoRecordEvent.Start -> {
|
||||||
@ -470,7 +452,6 @@ class CameraXPreview(
|
|||||||
playStopVideoRecordingSoundIfEnabled()
|
playStopVideoRecordingSoundIfEnabled()
|
||||||
listener.onVideoRecordingStopped()
|
listener.onVideoRecordingStopped()
|
||||||
if (recordEvent.hasError()) {
|
if (recordEvent.hasError()) {
|
||||||
Log.e(TAG, "recording failed:", recordEvent.cause)
|
|
||||||
cameraErrorHandler.handleVideoRecordingError(recordEvent.error)
|
cameraErrorHandler.handleVideoRecordingError(recordEvent.error)
|
||||||
} else {
|
} else {
|
||||||
listener.onMediaSaved(mediaOutput.uri ?: recordEvent.outputResults.outputUri)
|
listener.onMediaSaved(mediaOutput.uri ?: recordEvent.outputResults.outputUri)
|
||||||
@ -478,7 +459,6 @@ class CameraXPreview(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Recording started")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playShutterSoundIfEnabled() {
|
private fun playShutterSoundIfEnabled() {
|
||||||
|
Reference in New Issue
Block a user