commit
b0fdbc78a4
|
@ -141,7 +141,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
handleTogglePhotoVideo()
|
||||
checkButtons()
|
||||
}
|
||||
toggleBottomButtons(false)
|
||||
toggleBottomButtons(enabled = true)
|
||||
mOrientationEventListener.enable()
|
||||
}
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
@ -429,11 +429,9 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
|
||||
private fun handleShutter() {
|
||||
if (mIsInPhotoMode) {
|
||||
toggleBottomButtons(true)
|
||||
toggleBottomButtons(enabled = false)
|
||||
change_resolution.isEnabled = true
|
||||
mPreview?.tryTakePicture()
|
||||
shutter_animation.alpha = 1.0f
|
||||
shutter_animation.animate().alpha(0f).setDuration(CAPTURE_ANIMATION_DURATION).start()
|
||||
} else {
|
||||
mPreview?.toggleRecording()
|
||||
}
|
||||
|
@ -471,7 +469,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
hideTimer()
|
||||
togglePhotoVideoMode()
|
||||
checkButtons()
|
||||
toggleBottomButtons(false)
|
||||
toggleBottomButtons(enabled = true)
|
||||
}
|
||||
|
||||
private fun togglePhotoVideoMode() {
|
||||
|
@ -640,14 +638,20 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
toggle_camera.setImageResource(if (frontCamera) R.drawable.ic_camera_rear_vector else R.drawable.ic_camera_front_vector)
|
||||
}
|
||||
|
||||
override fun toggleBottomButtons(hide: Boolean) {
|
||||
override fun toggleBottomButtons(enabled: Boolean) {
|
||||
runOnUiThread {
|
||||
shutter.isClickable = !hide
|
||||
toggle_camera.isClickable = !hide
|
||||
toggle_flash.isClickable = !hide
|
||||
shutter.isClickable = enabled
|
||||
preview_view.isEnabled = enabled
|
||||
toggle_camera.isClickable = enabled
|
||||
toggle_flash.isClickable = enabled
|
||||
}
|
||||
}
|
||||
|
||||
override fun shutterAnimation() {
|
||||
shutter_animation.alpha = 1.0f
|
||||
shutter_animation.animate().alpha(0f).setDuration(CAPTURE_ANIMATION_DURATION).start()
|
||||
}
|
||||
|
||||
override fun onMediaSaved(uri: Uri) {
|
||||
change_resolution.isEnabled = true
|
||||
loadLastTakenMedia(uri)
|
||||
|
|
|
@ -423,6 +423,7 @@ class CameraXPreview(
|
|||
val mediaOutput = mediaOutputHelper.getImageMediaOutput()
|
||||
imageCapture.takePicture(mainExecutor, object : OnImageCapturedCallback() {
|
||||
override fun onCaptureSuccess(image: ImageProxy) {
|
||||
listener.shutterAnimation()
|
||||
playShutterSoundIfEnabled()
|
||||
ensureBackgroundThread {
|
||||
image.use {
|
||||
|
@ -430,7 +431,7 @@ class CameraXPreview(
|
|||
val imageBytes = ImageUtil.jpegImageToJpegByteArray(image)
|
||||
val bitmap = BitmapUtils.makeBitmap(imageBytes)
|
||||
activity.runOnUiThread {
|
||||
listener.toggleBottomButtons(false)
|
||||
listener.toggleBottomButtons(enabled = true)
|
||||
if (bitmap != null) {
|
||||
listener.onImageCaptured(bitmap)
|
||||
} else {
|
||||
|
@ -447,7 +448,7 @@ class CameraXPreview(
|
|||
saveExifAttributes = config.savePhotoMetadata,
|
||||
onImageSaved = { savedUri ->
|
||||
activity.runOnUiThread {
|
||||
listener.toggleBottomButtons(false)
|
||||
listener.toggleBottomButtons(enabled = true)
|
||||
listener.onMediaSaved(savedUri)
|
||||
}
|
||||
},
|
||||
|
@ -465,7 +466,7 @@ class CameraXPreview(
|
|||
}
|
||||
|
||||
private fun handleImageCaptureError(exception: ImageCaptureException) {
|
||||
listener.toggleBottomButtons(false)
|
||||
listener.toggleBottomButtons(enabled = true)
|
||||
cameraErrorHandler.handleImageCaptureError(exception.imageCaptureError)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ interface CameraXPreviewListener {
|
|||
fun setHasFrontAndBackCamera(hasFrontAndBack: Boolean)
|
||||
fun setFlashAvailable(available: Boolean)
|
||||
fun onChangeCamera(frontCamera: Boolean)
|
||||
fun toggleBottomButtons(hide: Boolean)
|
||||
fun toggleBottomButtons(enabled: Boolean)
|
||||
fun shutterAnimation()
|
||||
fun onMediaSaved(uri: Uri)
|
||||
fun onImageCaptured(bitmap: Bitmap)
|
||||
fun onChangeFlashMode(flashMode: Int)
|
||||
|
|
Loading…
Reference in New Issue