mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 00:17:41 +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
|
val viewConfiguration = LocalViewConfiguration.current
|
||||||
var volumeKeyPressStartTime by remember { mutableStateOf(0L) }
|
var volumeKeyPressStartTime by remember { mutableStateOf(0L) }
|
||||||
var isRecordingFromVolumeKey by remember { mutableStateOf(false) }
|
var isRecordingFromVolumeKey by remember { mutableStateOf(false) }
|
||||||
|
var activeVolumeKeyCode by remember { mutableStateOf(0) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
focusRequester.requestFocus()
|
focusRequester.requestFocus()
|
||||||
@@ -165,9 +166,13 @@ fun BoxScope.StandardCameraHud(
|
|||||||
when (nativeEvent.action) {
|
when (nativeEvent.action) {
|
||||||
KeyEvent.ACTION_DOWN -> {
|
KeyEvent.ACTION_DOWN -> {
|
||||||
if (nativeEvent.repeatCount == 0) {
|
if (nativeEvent.repeatCount == 0) {
|
||||||
volumeKeyPressStartTime = nativeEvent.eventTime
|
if (activeVolumeKeyCode == 0) {
|
||||||
isRecordingFromVolumeKey = false
|
activeVolumeKeyCode = keyCode
|
||||||
} else if (!isRecordingFromVolumeKey &&
|
volumeKeyPressStartTime = nativeEvent.eventTime
|
||||||
|
isRecordingFromVolumeKey = false
|
||||||
|
}
|
||||||
|
} else if (keyCode == activeVolumeKeyCode &&
|
||||||
|
!isRecordingFromVolumeKey &&
|
||||||
volumeKeyPressStartTime > 0 &&
|
volumeKeyPressStartTime > 0 &&
|
||||||
nativeEvent.eventTime - volumeKeyPressStartTime >= viewConfiguration.longPressTimeoutMillis
|
nativeEvent.eventTime - volumeKeyPressStartTime >= viewConfiguration.longPressTimeoutMillis
|
||||||
) {
|
) {
|
||||||
@@ -183,13 +188,16 @@ fun BoxScope.StandardCameraHud(
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.ACTION_UP -> {
|
KeyEvent.ACTION_UP -> {
|
||||||
if (isRecordingFromVolumeKey) {
|
if (keyCode == activeVolumeKeyCode) {
|
||||||
isRecordingFromVolumeKey = false
|
if (isRecordingFromVolumeKey) {
|
||||||
emitter(StandardCameraHudEvents.VideoCaptureStopped)
|
isRecordingFromVolumeKey = false
|
||||||
} else if (volumeKeyPressStartTime > 0) {
|
emitter(StandardCameraHudEvents.VideoCaptureStopped)
|
||||||
emitter(StandardCameraHudEvents.PhotoCaptureTriggered)
|
} else if (volumeKeyPressStartTime > 0) {
|
||||||
|
emitter(StandardCameraHudEvents.PhotoCaptureTriggered)
|
||||||
|
}
|
||||||
|
volumeKeyPressStartTime = 0
|
||||||
|
activeVolumeKeyCode = 0
|
||||||
}
|
}
|
||||||
volumeKeyPressStartTime = 0
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user