From 47ce8584815f3ee424cb65ba752ef29127d9772f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 20:27:00 +0000 Subject: [PATCH] fix: PiP portrait aspect ratio and PiP close (X) button hangup - Restore Rational(9, 16) portrait aspect ratio for PiP window - Add onStop handler: when PiP is dismissed via X button, hang up the call and finish the activity (mirrors PipVideoActivity pattern) - onPictureInPictureModeChanged also hangs up if activity is finishing https://claude.ai/code/session_01Ak5tTkujpjNG1r5ASuPipZ --- .../amethyst/ui/call/CallActivity.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallActivity.kt index c21c02182c..03a4e78f9f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallActivity.kt @@ -98,9 +98,32 @@ class CallActivity : AppCompatActivity() { enterPipIfActive() } + @OptIn(DelicateCoroutinesApi::class) override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { super.onPictureInPictureModeChanged(isInPictureInPictureMode) isInPipMode.value = isInPictureInPictureMode + + if (!isInPictureInPictureMode) { + // User pressed the X button on PiP or expanded it. + // If the activity is finishing (user dismissed PiP), hang up. + if (isFinishing) { + GlobalScope.launch { ActiveCallHolder.callManager?.hangup() } + } + } + } + + @OptIn(DelicateCoroutinesApi::class) + override fun onStop() { + super.onStop() + // When PiP is dismissed (X button), Android stops the activity. + // If we're not in PiP anymore and the activity is stopping, hang up and finish. + if (!isInPictureInPictureMode) { + val state = ActiveCallHolder.callManager?.state?.value + if (state is CallState.Connected || state is CallState.Connecting || state is CallState.Offering) { + GlobalScope.launch { ActiveCallHolder.callManager?.hangup() } + } + finishAndRemoveTask() + } } @OptIn(DelicateCoroutinesApi::class) @@ -148,7 +171,7 @@ class CallActivity : AppCompatActivity() { val builder = PictureInPictureParams .Builder() - .setAspectRatio(Rational(16, 9)) + .setAspectRatio(Rational(9, 16)) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setActions(buildPipActions())