Skip to content

Commit

Permalink
Fix several small bugs with foldable calling.
Browse files Browse the repository at this point in the history
* Set proper aspect ratio of pip in landscape mode.
* Fix some fade and adjustment from new UI states.
  • Loading branch information
alex-signal committed Aug 6, 2021
1 parent a9bbee3 commit c9597ef
Showing 1 changed file with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MenuItem;
Expand Down Expand Up @@ -288,7 +289,7 @@ public void onWindowSystemUiVisibilityChanged(int visible) {
if ((visible & SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
if (controls.adjustForFold()) {
pictureInPictureGestureHelper.clearVerticalBoundaries();
pictureInPictureGestureHelper.setTopVerticalBoundary(toolbar.getBottom());
pictureInPictureGestureHelper.setTopVerticalBoundary(toolbar.getTop());
} else {
pictureInPictureGestureHelper.setTopVerticalBoundary(toolbar.getBottom());
pictureInPictureGestureHelper.setBottomVerticalBoundary(videoToggle.getTop());
Expand Down Expand Up @@ -354,7 +355,10 @@ public void updateCallParticipants(@NonNull CallParticipantsViewState callPartic

pagerAdapter.submitList(pages);
recyclerAdapter.submitList(state.getListParticipants());
updateLocalCallParticipant(state.getLocalRenderState(), state.getLocalParticipant(), state.getFocusedParticipant());

boolean displaySmallSelfPipInLandscape = !isPortrait && isLandscapeEnabled;

updateLocalCallParticipant(state.getLocalRenderState(), state.getLocalParticipant(), state.getFocusedParticipant(), displaySmallSelfPipInLandscape);

if (state.isLargeVideoGroup() && !state.isInPipMode() && !state.isFolded()) {
layoutParticipantsForLargeCount();
Expand All @@ -363,7 +367,11 @@ public void updateCallParticipants(@NonNull CallParticipantsViewState callPartic
}
}

public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state, @NonNull CallParticipant localCallParticipant, @NonNull CallParticipant focusedParticipant) {
public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state,
@NonNull CallParticipant localCallParticipant,
@NonNull CallParticipant focusedParticipant,
boolean displaySmallSelfPipInLandscape)
{
largeLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);

smallLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
Expand Down Expand Up @@ -396,7 +404,7 @@ public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state, @N
break;
case SMALL_RECTANGLE:
smallLocalRenderFrame.setVisibility(View.VISIBLE);
animatePipToLargeRectangle();
animatePipToLargeRectangle(displaySmallSelfPipInLandscape);

largeLocalRender.attachBroadcastVideoSink(null);
largeLocalRenderFrame.setVisibility(View.GONE);
Expand Down Expand Up @@ -615,13 +623,23 @@ public void setWebRtcControls(@NonNull WebRtcControls webRtcControls) {
}
}

if (webRtcControls.adjustForFold() && webRtcControls.isFadeOutEnabled() && !controls.adjustForFold()) {
scheduleFadeOut();
}

controls = webRtcControls;

if (!controls.isFadeOutEnabled()) {
controlsVisible = true;
}

if (!visibleViewSet.equals(lastVisibleSet) || !controls.isFadeOutEnabled()) {
if (!visibleViewSet.equals(lastVisibleSet) ||
!controls.isFadeOutEnabled()) {

if (controlsListener != null) {
controlsListener.showSystemUI();
}

fadeInNewUiState(lastVisibleSet, webRtcControls.displaySmallOngoingCallButtons());
}

Expand Down Expand Up @@ -710,8 +728,15 @@ public void onAnimationHasFinished() {
});
}

private void animatePipToLargeRectangle() {
ResizeAnimation animation = new ResizeAnimation(smallLocalRenderFrame, ViewUtil.dpToPx(90), ViewUtil.dpToPx(160));
private void animatePipToLargeRectangle(boolean isLandscape) {
final Point dimens;
if (isLandscape) {
dimens = new Point(ViewUtil.dpToPx(160), ViewUtil.dpToPx(90));
} else {
dimens = new Point(ViewUtil.dpToPx(90), ViewUtil.dpToPx(160));
}

ResizeAnimation animation = new ResizeAnimation(smallLocalRenderFrame, dimens.x, dimens.y);
animation.setDuration(PIP_RESIZE_DURATION);
animation.setAnimationListener(new SimpleAnimationListener() {
@Override
Expand Down Expand Up @@ -777,7 +802,7 @@ private int withControlsHeight(int margin) {
return 0;
}

return controlsVisible ? margin + CONTROLS_HEIGHT : margin;
return (controlsVisible || controls.adjustForFold()) ? margin + CONTROLS_HEIGHT : margin;
}

private void layoutParticipants() {
Expand Down Expand Up @@ -862,7 +887,7 @@ private void fadeInNewUiState(@NonNull Set<View> previouslyVisibleViewSet, boole
}

private void adjustParticipantsRecycler(@NonNull ConstraintSet constraintSet) {
if (controlsVisible) {
if (controlsVisible || controls.adjustForFold()) {
constraintSet.connect(R.id.call_screen_participants_recycler, ConstraintSet.BOTTOM, R.id.call_screen_video_toggle, ConstraintSet.TOP);
} else {
constraintSet.connect(R.id.call_screen_participants_recycler, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
Expand Down

0 comments on commit c9597ef

Please sign in to comment.