Improve transition to PiP mode.

Use setAutoEnterEnable to true for smooth transition to
Picture-in-Picture when in gestural navigation mode.

Closes #12878
This commit is contained in:
Aaron Labiaga
2023-04-05 12:35:14 -06:00
committed by Greyson Parrelli
parent c834cb6ff7
commit 0156e74f5a

View File

@@ -125,6 +125,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
private WindowLayoutInfoConsumer windowLayoutInfoConsumer; private WindowLayoutInfoConsumer windowLayoutInfoConsumer;
private WindowInfoTrackerCallbackAdapter windowInfoTrackerCallbackAdapter; private WindowInfoTrackerCallbackAdapter windowInfoTrackerCallbackAdapter;
private ThrottledDebouncer requestNewSizesThrottle; private ThrottledDebouncer requestNewSizesThrottle;
private PictureInPictureParams.Builder pipBuilderParams;
private Disposable ephemeralStateDisposable = Disposable.empty(); private Disposable ephemeralStateDisposable = Disposable.empty();
@@ -156,6 +157,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
initializeResources(); initializeResources();
initializeViewModel(isLandscapeEnabled); initializeViewModel(isLandscapeEnabled);
initializePictureInPictureParams();
processIntent(getIntent()); processIntent(getIntent());
@@ -275,14 +277,16 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
} }
private boolean enterPipModeIfPossible() { private boolean enterPipModeIfPossible() {
if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) { if (isSystemPipEnabledAndAvailable()) {
PictureInPictureParams params = new PictureInPictureParams.Builder() if (viewModel.canEnterPipMode()) {
.setAspectRatio(new Rational(9, 16)) enterPictureInPictureMode(pipBuilderParams.build());
.build(); CallParticipantsListDialog.dismiss(getSupportFragmentManager());
enterPictureInPictureMode(params);
CallParticipantsListDialog.dismiss(getSupportFragmentManager());
return true; return true;
}
if (Build.VERSION.SDK_INT >= 31) {
pipBuilderParams.setAutoEnterEnabled(false);
}
} }
return false; return false;
} }
@@ -362,6 +366,19 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
}); });
} }
private void initializePictureInPictureParams() {
if (isSystemPipEnabledAndAvailable()) {
pipBuilderParams = new PictureInPictureParams.Builder();
pipBuilderParams.setAspectRatio(new Rational(9, 16));
if (Build.VERSION.SDK_INT >= 31) {
pipBuilderParams.setAutoEnterEnabled(true);
}
if (Build.VERSION.SDK_INT >= 26) {
setPictureInPictureParams(pipBuilderParams.build());
}
}
}
private void handleViewModelEvent(@NonNull WebRtcCallViewModel.Event event) { private void handleViewModelEvent(@NonNull WebRtcCallViewModel.Event event) {
if (event instanceof WebRtcCallViewModel.Event.StartCall) { if (event instanceof WebRtcCallViewModel.Event.StartCall) {
startCall(((WebRtcCallViewModel.Event.StartCall) event).isVideoCall()); startCall(((WebRtcCallViewModel.Event.StartCall) event).isVideoCall());