Skip to content

Commit

Permalink
Improve transition to PiP mode.
Browse files Browse the repository at this point in the history
Use setAutoEnterEnable to true for smooth transition to
Picture-in-Picture when in gestural navigation mode.

Closes #12878
  • Loading branch information
alabiaga authored and greyson-signal committed Apr 12, 2023
1 parent c834cb6 commit 0156e74
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
private WindowLayoutInfoConsumer windowLayoutInfoConsumer;
private WindowInfoTrackerCallbackAdapter windowInfoTrackerCallbackAdapter;
private ThrottledDebouncer requestNewSizesThrottle;
private PictureInPictureParams.Builder pipBuilderParams;

private Disposable ephemeralStateDisposable = Disposable.empty();

Expand Down Expand Up @@ -156,6 +157,7 @@ public void onCreate(Bundle savedInstanceState) {

initializeResources();
initializeViewModel(isLandscapeEnabled);
initializePictureInPictureParams();

processIntent(getIntent());

Expand Down Expand Up @@ -275,14 +277,16 @@ public void onBackPressed() {
}

private boolean enterPipModeIfPossible() {
if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) {
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(new Rational(9, 16))
.build();
enterPictureInPictureMode(params);
CallParticipantsListDialog.dismiss(getSupportFragmentManager());
if (isSystemPipEnabledAndAvailable()) {
if (viewModel.canEnterPipMode()) {
enterPictureInPictureMode(pipBuilderParams.build());
CallParticipantsListDialog.dismiss(getSupportFragmentManager());

return true;
return true;
}
if (Build.VERSION.SDK_INT >= 31) {
pipBuilderParams.setAutoEnterEnabled(false);
}
}
return false;
}
Expand Down Expand Up @@ -362,6 +366,19 @@ private void initializeViewModel(boolean isLandscapeEnabled) {
});
}

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) {
if (event instanceof WebRtcCallViewModel.Event.StartCall) {
startCall(((WebRtcCallViewModel.Event.StartCall) event).isVideoCall());
Expand Down

1 comment on commit 0156e74

@robotwombat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @alabiaga!

Please sign in to comment.