Hide camera switch icon during calls for devices with 1 or fewer cameras.

This commit is contained in:
Nicholas Tinsley
2024-03-29 17:04:55 -04:00
parent 7a9c01e6e5
commit 0014a2cba7
3 changed files with 53 additions and 46 deletions

View File

@@ -251,7 +251,7 @@ public class CallParticipantView extends ConstraintLayout {
* Adjust UI elements for the various self PIP positions. If called after a {@link TransitionManager#beginDelayedTransition(ViewGroup, Transition)},
* the changes to the UI elements will animate.
*/
void setSelfPipMode(@NonNull SelfPipMode selfPipMode) {
void setSelfPipMode(@NonNull SelfPipMode selfPipMode, boolean isMoreThanOneCameraAvailable) {
Preconditions.checkArgument(selfPipMode != SelfPipMode.NOT_SELF_PIP);
if (this.selfPipMode == selfPipMode) {
@@ -282,26 +282,30 @@ public class CallParticipantView extends ConstraintLayout {
ViewUtil.dpToPx(6)
);
constraints.setVisibility(R.id.call_participant_switch_camera, View.VISIBLE);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.END,
ViewUtil.dpToPx(6)
);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.BOTTOM,
ViewUtil.dpToPx(6)
);
constraints.constrainWidth(R.id.call_participant_switch_camera, ViewUtil.dpToPx(28));
constraints.constrainHeight(R.id.call_participant_switch_camera, ViewUtil.dpToPx(28));
if (isMoreThanOneCameraAvailable) {
constraints.setVisibility(R.id.call_participant_switch_camera, View.VISIBLE);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.END,
ViewUtil.dpToPx(6)
);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.BOTTOM,
ViewUtil.dpToPx(6)
);
constraints.constrainWidth(R.id.call_participant_switch_camera, ViewUtil.dpToPx(28));
constraints.constrainHeight(R.id.call_participant_switch_camera, ViewUtil.dpToPx(28));
ViewGroup.LayoutParams params = switchCameraIcon.getLayoutParams();
params.width = params.height = ViewUtil.dpToPx(16);
switchCameraIcon.setLayoutParams(params);
ViewGroup.LayoutParams params = switchCameraIcon.getLayoutParams();
params.width = params.height = ViewUtil.dpToPx(16);
switchCameraIcon.setLayoutParams(params);
switchCameraIconFrame.setClickable(false);
switchCameraIconFrame.setEnabled(false);
switchCameraIconFrame.setClickable(false);
switchCameraIconFrame.setEnabled(false);
} else {
constraints.setVisibility(R.id.call_participant_switch_camera, View.GONE);
}
}
case EXPANDED_SELF_PIP -> {
constraints.connect(
@@ -321,26 +325,30 @@ public class CallParticipantView extends ConstraintLayout {
ViewUtil.dpToPx(8)
);
constraints.setVisibility(R.id.call_participant_switch_camera, View.VISIBLE);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.END,
ViewUtil.dpToPx(8)
);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.BOTTOM,
ViewUtil.dpToPx(8)
);
constraints.constrainWidth(R.id.call_participant_switch_camera, ViewUtil.dpToPx(48));
constraints.constrainHeight(R.id.call_participant_switch_camera, ViewUtil.dpToPx(48));
if (isMoreThanOneCameraAvailable) {
constraints.setVisibility(R.id.call_participant_switch_camera, View.VISIBLE);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.END,
ViewUtil.dpToPx(8)
);
constraints.setMargin(
R.id.call_participant_switch_camera,
ConstraintSet.BOTTOM,
ViewUtil.dpToPx(8)
);
constraints.constrainWidth(R.id.call_participant_switch_camera, ViewUtil.dpToPx(48));
constraints.constrainHeight(R.id.call_participant_switch_camera, ViewUtil.dpToPx(48));
ViewGroup.LayoutParams params = switchCameraIcon.getLayoutParams();
params.width = params.height = ViewUtil.dpToPx(24);
switchCameraIcon.setLayoutParams(params);
ViewGroup.LayoutParams params = switchCameraIcon.getLayoutParams();
params.width = params.height = ViewUtil.dpToPx(24);
switchCameraIcon.setLayoutParams(params);
switchCameraIconFrame.setClickable(true);
switchCameraIconFrame.setEnabled(true);
switchCameraIconFrame.setClickable(true);
switchCameraIconFrame.setEnabled(true);
} else {
constraints.setVisibility(R.id.call_participant_switch_camera, View.GONE);
}
}
case MINI_SELF_PIP -> {
constraints.connect(

View File

@@ -506,11 +506,11 @@ public class WebRtcCallView extends InsetAwareConstraintLayout {
if (state == WebRtcLocalRenderState.EXPANDED) {
pictureInPictureExpansionHelper.beginExpandTransition();
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.EXPANDED_SELF_PIP);
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.EXPANDED_SELF_PIP, localCallParticipant.isMoreThanOneCameraAvailable());
return;
} else if ((state.isAnySmall() || state == WebRtcLocalRenderState.GONE) && pictureInPictureExpansionHelper.isExpandedOrExpanding()) {
pictureInPictureExpansionHelper.beginShrinkTransition();
smallLocalRender.setSelfPipMode(pictureInPictureExpansionHelper.isMiniSize() ? CallParticipantView.SelfPipMode.MINI_SELF_PIP : CallParticipantView.SelfPipMode.NORMAL_SELF_PIP);
smallLocalRender.setSelfPipMode(pictureInPictureExpansionHelper.isMiniSize() ? CallParticipantView.SelfPipMode.MINI_SELF_PIP : CallParticipantView.SelfPipMode.NORMAL_SELF_PIP, localCallParticipant.isMoreThanOneCameraAvailable());
if (state != WebRtcLocalRenderState.GONE) {
return;
@@ -526,14 +526,14 @@ public class WebRtcCallView extends InsetAwareConstraintLayout {
break;
case SMALL_RECTANGLE:
smallLocalRenderFrame.setVisibility(View.VISIBLE);
animatePipToLargeRectangle(displaySmallSelfPipInLandscape);
animatePipToLargeRectangle(displaySmallSelfPipInLandscape, localCallParticipant.isMoreThanOneCameraAvailable());
largeLocalRender.attachBroadcastVideoSink(null);
largeLocalRenderFrame.setVisibility(View.GONE);
break;
case SMALLER_RECTANGLE:
smallLocalRenderFrame.setVisibility(View.VISIBLE);
animatePipToSmallRectangle();
animatePipToSmallRectangle(localCallParticipant.isMoreThanOneCameraAvailable());
largeLocalRender.attachBroadcastVideoSink(null);
largeLocalRenderFrame.setVisibility(View.GONE);
@@ -785,7 +785,7 @@ public class WebRtcCallView extends InsetAwareConstraintLayout {
}
}
private void animatePipToLargeRectangle(boolean isLandscape) {
private void animatePipToLargeRectangle(boolean isLandscape, boolean moreThanOneCameraAvailable) {
final Point dimens;
if (isLandscape) {
dimens = new Point(ViewUtil.dpToPx(PictureInPictureExpansionHelper.NORMAL_PIP_HEIGHT_DP),
@@ -802,10 +802,10 @@ public class WebRtcCallView extends InsetAwareConstraintLayout {
}
});
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.NORMAL_SELF_PIP);
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.NORMAL_SELF_PIP, moreThanOneCameraAvailable);
}
private void animatePipToSmallRectangle() {
private void animatePipToSmallRectangle(boolean moreThanOneCameraAvailable) {
pictureInPictureExpansionHelper.startDefaultSizeTransition(new Point(ViewUtil.dpToPx(PictureInPictureExpansionHelper.MINI_PIP_WIDTH_DP),
ViewUtil.dpToPx(PictureInPictureExpansionHelper.MINI_PIP_HEIGHT_DP)),
new PictureInPictureExpansionHelper.Callback() {
@@ -815,7 +815,7 @@ public class WebRtcCallView extends InsetAwareConstraintLayout {
}
});
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.MINI_SELF_PIP);
smallLocalRender.setSelfPipMode(CallParticipantView.SelfPipMode.MINI_SELF_PIP, moreThanOneCameraAvailable);
}
private void toggleControls() {

View File

@@ -428,7 +428,6 @@ private fun ContentPreviewWithUserSetDisplayName() {
}
}
@Preview(name = "Light Theme", group = "content", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark Theme", group = "content", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable