From b646e69b6bc1efea5cb6ffde2cb72177967873ed Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 12 Dec 2023 12:56:54 -0500 Subject: [PATCH] Fix self-PIP boundaries in calls. --- .../securesms/WebRtcCallActivity.java | 10 --------- .../webrtc/PictureInPictureGestureHelper.java | 21 ++++++++++++------- .../components/webrtc/WebRtcCallView.java | 12 ++--------- .../controls/ControlsAndInfoController.kt | 4 ++-- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index 5bfd8844cb..a621a24980 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -991,16 +991,6 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan controlsAndInfo.toggleControls(); } - @Override - public void showSystemUI() { - fullscreenHelper.showSystemUI(); - } - - @Override - public void hideSystemUI() { - fullscreenHelper.hideSystemUI(); - } - @Override public void onAudioOutputChanged(@NonNull WebRtcAudioOutput audioOutput) { maybeDisplaySpeakerphonePopup(audioOutput); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/PictureInPictureGestureHelper.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/PictureInPictureGestureHelper.java index e462a00aed..336e41f491 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/PictureInPictureGestureHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/PictureInPictureGestureHelper.java @@ -34,7 +34,7 @@ public class PictureInPictureGestureHelper extends GestureDetector.SimpleOnGestu private int pipWidth; private int pipHeight; - private int activePointerId = MotionEvent.INVALID_POINTER_ID; + private int activePointerId = MotionEvent.INVALID_POINTER_ID; private float lastTouchX; private float lastTouchY; private int extraPaddingTop; @@ -45,7 +45,9 @@ public class PictureInPictureGestureHelper extends GestureDetector.SimpleOnGestu private int maximumFlingVelocity; private boolean isLockedToBottomEnd; private Interpolator interpolator; - private Corner currentCornerPosition = Corner.BOTTOM_RIGHT; + private Corner currentCornerPosition = Corner.BOTTOM_RIGHT; + private int previousTopBoundary = -1; + private int previousBottomBoundary = -1; @SuppressLint("ClickableViewAccessibility") public static PictureInPictureGestureHelper applyTo(@NonNull View child) { @@ -109,12 +111,12 @@ public class PictureInPictureGestureHelper extends GestureDetector.SimpleOnGestu this.interpolator = ADJUST_INTERPOLATOR; } - public void clearVerticalBoundaries() { - setTopVerticalBoundary(parent.getTop()); - setBottomVerticalBoundary(parent.getMeasuredHeight() + parent.getTop()); - } - public void setTopVerticalBoundary(int topBoundary) { + if (topBoundary == previousTopBoundary) { + return; + } + previousTopBoundary = topBoundary; + extraPaddingTop = topBoundary - parent.getTop(); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) child.getLayoutParams(); @@ -123,6 +125,11 @@ public class PictureInPictureGestureHelper extends GestureDetector.SimpleOnGestu } public void setBottomVerticalBoundary(int bottomBoundary) { + if (bottomBoundary == previousBottomBoundary) { + return; + } + previousBottomBoundary = bottomBoundary; + extraPaddingBottom = parent.getMeasuredHeight() + parent.getTop() - bottomBoundary; ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) child.getLayoutParams(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java index 10c0913468..d6f3bb0ed0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java @@ -379,15 +379,9 @@ public class WebRtcCallView extends InsetAwareConstraintLayout { @Override public void onWindowSystemUiVisibilityChanged(int visible) { if ((visible & SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { - if (controls.adjustForFold()) { - pictureInPictureGestureHelper.clearVerticalBoundaries(); - pictureInPictureGestureHelper.setTopVerticalBoundary(getPipBarrier().getTop()); - } else { - pictureInPictureGestureHelper.setTopVerticalBoundary(getPipBarrier().getBottom()); - pictureInPictureGestureHelper.setBottomVerticalBoundary(findViewById(R.id.call_controls_info_parent).getTop()); - } + pictureInPictureGestureHelper.setTopVerticalBoundary(collapsedToolbar.getBottom()); } else { - pictureInPictureGestureHelper.clearVerticalBoundaries(); + pictureInPictureGestureHelper.setTopVerticalBoundary(getStatusBarGuideline().getBottom()); } } @@ -961,8 +955,6 @@ public class WebRtcCallView extends InsetAwareConstraintLayout { public interface ControlsListener { void onStartCall(boolean isVideoCall); void onCancelStartCall(); - void showSystemUI(); - void hideSystemUI(); void onAudioOutputChanged(@NonNull WebRtcAudioOutput audioOutput); @RequiresApi(31) void onAudioOutputChanged31(@NonNull WebRtcAudioDevice audioOutput); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/controls/ControlsAndInfoController.kt b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/controls/ControlsAndInfoController.kt index fb2f543e8c..a2ef5336c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/controls/ControlsAndInfoController.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/controls/ControlsAndInfoController.kt @@ -104,8 +104,8 @@ class ControlsAndInfoController( behavior.state = BottomSheetBehavior.STATE_HIDDEN BottomSheetBehaviorHack.setNestedScrollingChild(behavior, callInfoComposeView) - coordinator.addOnLayoutChangeListener { _, _, top, _, bottom, _, _, _, _ -> - val guidelineTop = max(frame.top, (bottom - top) - behavior.peekHeight) + coordinator.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> + val guidelineTop = max(frame.top, coordinator.height - behavior.peekHeight) webRtcCallView.post { webRtcCallView.onControlTopChanged(guidelineTop) } }