mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 08:23:00 +01:00
Fix volume key interference during camera video recording.
This commit is contained in:
committed by
Alex Hart
parent
a0a962a94f
commit
bf28b90e89
@@ -122,6 +122,7 @@ fun BoxScope.StandardCameraHud(
|
||||
val viewConfiguration = LocalViewConfiguration.current
|
||||
var volumeKeyPressStartTime by remember { mutableStateOf(0L) }
|
||||
var isRecordingFromVolumeKey by remember { mutableStateOf(false) }
|
||||
var activeVolumeKeyCode by remember { mutableStateOf(0) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
focusRequester.requestFocus()
|
||||
@@ -165,9 +166,13 @@ fun BoxScope.StandardCameraHud(
|
||||
when (nativeEvent.action) {
|
||||
KeyEvent.ACTION_DOWN -> {
|
||||
if (nativeEvent.repeatCount == 0) {
|
||||
volumeKeyPressStartTime = nativeEvent.eventTime
|
||||
isRecordingFromVolumeKey = false
|
||||
} else if (!isRecordingFromVolumeKey &&
|
||||
if (activeVolumeKeyCode == 0) {
|
||||
activeVolumeKeyCode = keyCode
|
||||
volumeKeyPressStartTime = nativeEvent.eventTime
|
||||
isRecordingFromVolumeKey = false
|
||||
}
|
||||
} else if (keyCode == activeVolumeKeyCode &&
|
||||
!isRecordingFromVolumeKey &&
|
||||
volumeKeyPressStartTime > 0 &&
|
||||
nativeEvent.eventTime - volumeKeyPressStartTime >= viewConfiguration.longPressTimeoutMillis
|
||||
) {
|
||||
@@ -183,13 +188,16 @@ fun BoxScope.StandardCameraHud(
|
||||
}
|
||||
|
||||
KeyEvent.ACTION_UP -> {
|
||||
if (isRecordingFromVolumeKey) {
|
||||
isRecordingFromVolumeKey = false
|
||||
emitter(StandardCameraHudEvents.VideoCaptureStopped)
|
||||
} else if (volumeKeyPressStartTime > 0) {
|
||||
emitter(StandardCameraHudEvents.PhotoCaptureTriggered)
|
||||
if (keyCode == activeVolumeKeyCode) {
|
||||
if (isRecordingFromVolumeKey) {
|
||||
isRecordingFromVolumeKey = false
|
||||
emitter(StandardCameraHudEvents.VideoCaptureStopped)
|
||||
} else if (volumeKeyPressStartTime > 0) {
|
||||
emitter(StandardCameraHudEvents.PhotoCaptureTriggered)
|
||||
}
|
||||
volumeKeyPressStartTime = 0
|
||||
activeVolumeKeyCode = 0
|
||||
}
|
||||
volumeKeyPressStartTime = 0
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user