From c5aa333acc4f5d0539a36f3bdad1ce9a9ce71649 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 18 Jun 2020 20:06:52 -0700 Subject: [PATCH] Fix some minor issues with animating dismiss - Also decrease the magnetic field radius to bias towards moving the PIP vs dismissing it - Rotation was causing the bounds animation to be canceled while mTemporaryBounds was still set leading to the wrong starting bounds in the next orientation. In this case, we can always clear temporary bounds whenever synchronizing bounds. Change-Id: I721785ccabcd2ee94b7dfa9deeb306246bc2e4a3 Bug: 159390687 Bug: 159342554 Test: Drag pip while over dismiss area Test: Ensure fling to dismiss still works, target is smaller Test: Rotate while bounds animation is setting and ensure the touch is from the right starting bounds in the next orientation --- .../com/android/systemui/pip/phone/PipMotionHelper.java | 6 ++++++ .../com/android/systemui/pip/phone/PipTouchHandler.java | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java index 06c98d00cca71..26805050e8417 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java @@ -206,6 +206,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, void synchronizePinnedStackBounds() { cancelAnimations(); mBounds.set(mPipTaskOrganizer.getLastReportedBounds()); + mTemporaryBounds.setEmpty(); if (mPipTaskOrganizer.isInPip()) { mFloatingContentCoordinator.onContentMoved(this); @@ -274,6 +275,11 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, final float destinationX = targetCenter.x - (desiredWidth / 2f); final float destinationY = targetCenter.y - (desiredHeight / 2f); + // If we're already in the dismiss target area, then there won't be a move to set the + // temporary bounds, so just initialize it to the current bounds + if (mTemporaryBounds.isEmpty()) { + mTemporaryBounds.set(mBounds); + } mTemporaryBoundsPhysicsAnimator .spring(FloatProperties.RECT_X, destinationX, velX, mSpringConfig) .spring(FloatProperties.RECT_Y, destinationY, velY, mSpringConfig) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java index 199e3fadaf28b..7996316397e25 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java @@ -82,6 +82,9 @@ public class PipTouchHandler { /** Duration of the dismiss scrim fading in/out. */ private static final int DISMISS_TRANSITION_DURATION_MS = 200; + /* The multiplier to apply scale the target size by when applying the magnetic field radius */ + private static final float MAGNETIC_FIELD_RADIUS_MULTIPLIER = 1.25f; + // Allow dragging the PIP to a location to close it private final boolean mEnableDismissDragToEdge; // Allow PIP to resize to a slightly bigger state upon touch @@ -330,8 +333,9 @@ public class PipTouchHandler { R.dimen.floating_dismiss_bottom_margin); mTargetView.setLayoutParams(newParams); - // Set the magnetic field radius equal to twice the size of the target. - mMagneticTarget.setMagneticFieldRadiusPx(targetSize * 2); + // Set the magnetic field radius equal to the target size from the center of the target + mMagneticTarget.setMagneticFieldRadiusPx( + (int) (targetSize * MAGNETIC_FIELD_RADIUS_MULTIPLIER)); } private boolean shouldShowResizeHandle() { @@ -953,7 +957,6 @@ public class PipTouchHandler { } final PointF vel = touchState.getVelocity(); - final float velocity = PointF.length(vel.x, vel.y); if (touchState.isDragging()) { if (mMenuState != MENU_STATE_NONE) {