From c6c4988583049fc6467070c4941fafba00b05f34 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Wed, 4 Aug 2021 10:57:21 -0300 Subject: [PATCH] Apply proper rules for foldable aspect scaling in landscape and tabletop modes. --- .../components/webrtc/CallParticipantView.java | 4 ++++ .../webrtc/CallParticipantsLayout.java | 11 ++++++----- .../webrtc/CallParticipantsLayoutStrategies.kt | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java index 8de91fc1f..12695edcc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java @@ -105,6 +105,10 @@ public class CallParticipantView extends ConstraintLayout { renderer.setScalingType(scalingType); } + void setScalingType(@NonNull RendererCommon.ScalingType scalingTypeMatchOrientation, @NonNull RendererCommon.ScalingType scalingTypeMismatchOrientation) { + renderer.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation); + } + void setCallParticipant(@NonNull CallParticipant participant) { boolean participantChanged = recipientId == null || !recipientId.equals(participant.getRecipient().getId()); recipientId = participant.getRecipient().getId(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java index 648923258..85b49758c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java @@ -115,11 +115,7 @@ public class CallParticipantsLayout extends FlexboxLayout { callParticipantView.setCallParticipant(participant); callParticipantView.setRenderInPip(shouldRenderInPip); - if (participant.isScreenSharing()) { - callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - } else { - callParticipantView.setScalingType(isPortrait || count < 3 ? RendererCommon.ScalingType.SCALE_ASPECT_FILL : RendererCommon.ScalingType.SCALE_ASPECT_BALANCED); - } + layoutStrategy.setChildScaling(participant, callParticipantView, isPortrait, count); if (count > 1) { view.setPadding(MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING); @@ -150,6 +146,11 @@ public class CallParticipantsLayout extends FlexboxLayout { public interface LayoutStrategy { int getFlexDirection(); + void setChildScaling(@NonNull CallParticipant callParticipant, + @NonNull CallParticipantView callParticipantView, + boolean isPortrait, + int childCount); + void setChildLayoutParams(@NonNull View child, int childPosition, int childCount); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt index db6f990b2..e8007d253 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt @@ -3,12 +3,22 @@ package org.thoughtcrime.securesms.components.webrtc import android.view.View import com.google.android.flexbox.FlexDirection import com.google.android.flexbox.FlexboxLayout +import org.thoughtcrime.securesms.events.CallParticipant +import org.webrtc.RendererCommon object CallParticipantsLayoutStrategies { private object Portrait : CallParticipantsLayout.LayoutStrategy { override fun getFlexDirection(): Int = FlexDirection.ROW + override fun setChildScaling(callParticipant: CallParticipant, callParticipantView: CallParticipantView, isPortrait: Boolean, childCount: Int) { + if (callParticipant.isScreenSharing) { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT) + } else { + callParticipantView.setScalingType(if (isPortrait || childCount < 3) RendererCommon.ScalingType.SCALE_ASPECT_FILL else RendererCommon.ScalingType.SCALE_ASPECT_BALANCED) + } + } + override fun setChildLayoutParams(child: View, childPosition: Int, childCount: Int) { val params = child.layoutParams as FlexboxLayout.LayoutParams if (childCount < 3) { @@ -27,6 +37,14 @@ object CallParticipantsLayoutStrategies { private object Landscape : CallParticipantsLayout.LayoutStrategy { override fun getFlexDirection() = FlexDirection.COLUMN + override fun setChildScaling(callParticipant: CallParticipant, callParticipantView: CallParticipantView, isPortrait: Boolean, childCount: Int) { + if (callParticipant.isScreenSharing) { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT) + } else { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL, RendererCommon.ScalingType.SCALE_ASPECT_BALANCED) + } + } + override fun setChildLayoutParams(child: View, childPosition: Int, childCount: Int) { val params = child.layoutParams as FlexboxLayout.LayoutParams if (childCount < 4) {