Disable settings buttons during video recording

This commit is contained in:
Matéo Duparc 2023-04-17 18:50:46 +02:00
parent aea17aa7cb
commit eb4e13af46
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
2 changed files with 30 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import android.view.*
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation import android.view.animation.RotateAnimation
import android.widget.ImageButton
import android.widget.ImageView import android.widget.ImageView
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.Toast import android.widget.Toast
@ -533,21 +534,30 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener {
withAudioEnabled() withAudioEnabled()
} }
}?.start(executor) { }?.start(executor) {
val buttons = arrayOf(binding.imageCaptureMode, binding.imageRatio, binding.imageTimer, binding.imageModeSwitch, binding.imageCameraSwitch)
when (it) { when (it) {
is VideoRecordEvent.Start -> { is VideoRecordEvent.Start -> {
binding.recordVideoButton.setImageResource(R.drawable.stop_recording_video_button) binding.recordVideoButton.setImageResource(R.drawable.stop_recording_video_button)
for (i in buttons) {
i.isEnabled = false
i.alpha = 0.5F
}
isRecording = true isRecording = true
} }
is VideoRecordEvent.Finalize -> { is VideoRecordEvent.Finalize -> {
if (it.hasError()) { if (it.hasError()) {
it.cause?.printStackTrace() it.cause?.printStackTrace()
Toast.makeText(applicationContext, it.cause?.message, Toast.LENGTH_SHORT).show() Toast.makeText(applicationContext, it.cause?.message ?: ("Error: " + it.error), Toast.LENGTH_SHORT).show()
videoRecording?.close() videoRecording?.close()
videoRecording = null videoRecording = null
} else { } else {
Toast.makeText(applicationContext, getString(R.string.video_save_success, path), Toast.LENGTH_SHORT).show() Toast.makeText(applicationContext, getString(R.string.video_save_success, path), Toast.LENGTH_SHORT).show()
} }
binding.recordVideoButton.setImageResource(R.drawable.record_video_button) binding.recordVideoButton.setImageResource(R.drawable.record_video_button)
for (i in buttons) {
i.isEnabled = true
i.alpha = 1F
}
isRecording = false isRecording = false
} }
} }
@ -588,7 +598,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener {
orientedIcons.map { it.startAnimation(rotateAnimation) } orientedIcons.map { it.startAnimation(rotateAnimation) }
previousOrientation = realOrientation previousOrientation = realOrientation
imageCapture?.targetRotation = newOrientation imageCapture?.targetRotation = newOrientation
videoCapture?.setTargetRotation(newOrientation) videoCapture?.targetRotation = newOrientation
} }
} }

View File

@ -18,41 +18,49 @@
android:layout_height="40dp" android:layout_height="40dp"
android:layout_marginTop="20dp"> android:layout_marginTop="20dp">
<ImageView <ImageButton
android:id="@+id/image_capture_mode" android:id="@+id/image_capture_mode"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_high_quality" android:src="@drawable/icon_high_quality"
android:background="#00000000"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/image_ratio" app:layout_constraintEnd_toStartOf="@id/image_ratio"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>
<ImageView <ImageButton
android:id="@+id/image_ratio" android:id="@+id/image_ratio"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_aspect_ratio" android:src="@drawable/icon_aspect_ratio"
android:background="#00000000"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/image_timer" app:layout_constraintEnd_toStartOf="@id/image_timer"
app:layout_constraintStart_toEndOf="@id/image_capture_mode" app:layout_constraintStart_toEndOf="@id/image_capture_mode"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<ImageView <ImageButton
android:id="@+id/image_timer" android:id="@+id/image_timer"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_timer_off" android:src="@drawable/icon_timer_off"
android:background="#00000000"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/image_flash" app:layout_constraintEnd_toStartOf="@id/image_flash"
app:layout_constraintStart_toEndOf="@id/image_ratio" app:layout_constraintStart_toEndOf="@id/image_ratio"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<ImageView <ImageButton
android:id="@+id/image_flash" android:id="@+id/image_flash"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_flash_auto" android:src="@drawable/icon_flash_auto"
android:background="#00000000"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image_timer" app:layout_constraintStart_toEndOf="@id/image_timer"
@ -74,11 +82,13 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"> android:layout_marginBottom="30dp">
<ImageView <ImageButton
android:id="@+id/image_mode_switch" android:id="@+id/image_mode_switch"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_video" android:src="@drawable/icon_video"
android:background="#00000000"
android:scaleType="fitCenter"
android:layout_alignEnd="@id/layout_record_buttons" android:layout_alignEnd="@id/layout_record_buttons"
android:layout_marginEnd="120dp" android:layout_marginEnd="120dp"
android:layout_centerVertical="true"/> android:layout_centerVertical="true"/>
@ -104,11 +114,13 @@
</RelativeLayout> </RelativeLayout>
<ImageView <ImageButton
android:id="@+id/image_camera_switch" android:id="@+id/image_camera_switch"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:src="@drawable/icon_camera_front" android:src="@drawable/icon_camera_front"
android:background="#00000000"
android:scaleType="fitCenter"
android:layout_alignStart="@id/layout_record_buttons" android:layout_alignStart="@id/layout_record_buttons"
android:layout_marginStart="120dp" android:layout_marginStart="120dp"
android:layout_centerVertical="true"/> android:layout_centerVertical="true"/>