@@ -220,6 +220,36 @@ public void onSwipeRight() {
220220
221221 showActionBar ();
222222
223+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
224+ if (sharedPrefs .getBoolean ("prefPIP" , false ) && !isInMultiWindowMode ()) {
225+ Log .w ("PiP" , "prefPIP true" );
226+ int contentWidth = getWindow ().getDecorView ().getWidth ();
227+ int contentHeight = getWindow ().getDecorView ().getHeight ();
228+
229+ if (contentWidth > 0 && contentHeight > 0 ) {
230+ // Compute raw aspect ratio
231+ float rawRatio = (float ) contentWidth / contentHeight ;
232+
233+ // PiP bounds: [1/2.39, 2.39]
234+ final float MIN_ASPECT = 1f / 2.39f ;
235+ final float MAX_ASPECT = 2.39f ;
236+
237+ // Clamp
238+ float clampedRatio = Math .max (MIN_ASPECT , Math .min (rawRatio , MAX_ASPECT ));
239+
240+ // Recompute a Rational with the clamped width
241+ int clampedWidth = Math .round (clampedRatio * contentHeight );
242+ Rational pipAspectRatio = new Rational (clampedWidth , contentHeight );
243+
244+ PictureInPictureParams params = new PictureInPictureParams .Builder ()
245+ .setAspectRatio (pipAspectRatio )
246+ .setAutoEnterEnabled (true ) // Automatically enters PiP on Home press
247+ .build ();
248+ setPictureInPictureParams (params );
249+ }
250+ }
251+ }
252+
223253 // Use this check to determine whether BLE is supported on the device. Then you can
224254 // selectively disable BLE-related features.
225255 if (!getPackageManager ().hasSystemFeature (PackageManager .FEATURE_BLUETOOTH_LE )) {
@@ -547,6 +577,7 @@ public void onUserLeaveHint() {
547577 getWindow ().setAttributes (lp );
548578
549579 if (sharedPrefs .getBoolean ("prefPIP" , false ) && !isInMultiWindowMode ()) {
580+ Log .w ("PiP" , "prefPIP true" );
550581 int contentWidth = getWindow ().getDecorView ().getWidth ();
551582 int contentHeight = getWindow ().getDecorView ().getHeight ();
552583
@@ -578,7 +609,6 @@ public void onUserLeaveHint() {
578609 super .onUserLeaveHint ();
579610 }
580611
581-
582612 @ Override
583613 public void onPictureInPictureModeChanged (boolean isInPIPMode ) {
584614 if (isInPIPMode ) {
0 commit comments