Merge "Fix PIP snapping to incorrect location." into rvc-dev am: 6ad0b48b0a am: 738167d4fe am: 71a9f2115c am: 68a2caad57
Change-Id: I50a4ab6d5902e01109560818233e2197b2a2996f
This commit is contained in:
@@ -352,15 +352,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
|||||||
startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */);
|
startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Animates the PiP to the closest snap target.
|
|
||||||
*/
|
|
||||||
void animateToClosestSnapTarget() {
|
|
||||||
final Rect newBounds = new Rect();
|
|
||||||
mSnapAlgorithm.snapRectToClosestEdge(mBounds, mMovementBounds, newBounds);
|
|
||||||
animateToBounds(newBounds, mSpringConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animates PIP to the provided bounds, using physics animations and the given spring
|
* Animates PIP to the provided bounds, using physics animations and the given spring
|
||||||
* configuration
|
* configuration
|
||||||
|
|||||||
@@ -884,7 +884,6 @@ public class PipTouchHandler {
|
|||||||
|
|
||||||
final PointF vel = touchState.getVelocity();
|
final PointF vel = touchState.getVelocity();
|
||||||
final float velocity = PointF.length(vel.x, vel.y);
|
final float velocity = PointF.length(vel.x, vel.y);
|
||||||
final boolean isFling = velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond();
|
|
||||||
|
|
||||||
if (touchState.isDragging()) {
|
if (touchState.isDragging()) {
|
||||||
Runnable endAction = null;
|
Runnable endAction = null;
|
||||||
@@ -899,13 +898,9 @@ public class PipTouchHandler {
|
|||||||
endAction = mMenuController::hideMenu;
|
endAction = mMenuController::hideMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFling) {
|
mMotionHelper.flingToSnapTarget(vel.x, vel.y,
|
||||||
mMotionHelper.flingToSnapTarget(vel.x, vel.y,
|
PipTouchHandler.this::updateDismissFraction /* updateAction */,
|
||||||
PipTouchHandler.this::updateDismissFraction /* updateAction */,
|
endAction /* endAction */);
|
||||||
endAction /* endAction */);
|
|
||||||
} else {
|
|
||||||
mMotionHelper.animateToClosestSnapTarget();
|
|
||||||
}
|
|
||||||
} else if (mTouchState.isDoubleTap()) {
|
} else if (mTouchState.isDoubleTap()) {
|
||||||
// Expand to fullscreen if this is a double tap
|
// Expand to fullscreen if this is a double tap
|
||||||
// the PiP should be frozen until the transition ends
|
// the PiP should be frozen until the transition ends
|
||||||
|
|||||||
@@ -311,10 +311,25 @@ class PhysicsAnimator<T> private constructor (val target: T) {
|
|||||||
val springConfigCopy = springConfig.copy()
|
val springConfigCopy = springConfig.copy()
|
||||||
val toAtLeast = if (startVelocity < 0) flingConfig.min else flingConfig.max
|
val toAtLeast = if (startVelocity < 0) flingConfig.min else flingConfig.max
|
||||||
|
|
||||||
// If the fling needs to reach min/max, calculate the velocity required to do so and use
|
if (flingMustReachMinOrMax && isValidValue(toAtLeast)) {
|
||||||
// that if the provided start velocity is not sufficient.
|
val currentValue = property.getValue(target)
|
||||||
if (flingMustReachMinOrMax &&
|
val flingTravelDistance =
|
||||||
toAtLeast != -Float.MAX_VALUE && toAtLeast != Float.MAX_VALUE) {
|
startVelocity / (flingConfig.friction * FLING_FRICTION_SCALAR_MULTIPLIER)
|
||||||
|
val projectedFlingEndValue = currentValue + flingTravelDistance
|
||||||
|
val midpoint = (flingConfig.min + flingConfig.max) / 2
|
||||||
|
|
||||||
|
// If fling velocity is too low to push the target past the midpoint between min and
|
||||||
|
// max, then spring back towards the nearest edge, starting with the current velocity.
|
||||||
|
if ((startVelocity < 0 && projectedFlingEndValue > midpoint) ||
|
||||||
|
(startVelocity > 0 && projectedFlingEndValue < midpoint)) {
|
||||||
|
val toPosition =
|
||||||
|
if (projectedFlingEndValue < midpoint) flingConfig.min else flingConfig.max
|
||||||
|
if (isValidValue(toPosition)) {
|
||||||
|
return spring(property, toPosition, startVelocity, springConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Projected fling end value is past the midpoint, so fling forward.
|
||||||
val distanceToDestination = toAtLeast - property.getValue(target)
|
val distanceToDestination = toAtLeast - property.getValue(target)
|
||||||
|
|
||||||
// The minimum velocity required for the fling to end up at the given destination,
|
// The minimum velocity required for the fling to end up at the given destination,
|
||||||
@@ -345,6 +360,8 @@ class PhysicsAnimator<T> private constructor (val target: T) {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isValidValue(value: Float) = value < Float.MAX_VALUE && value > -Float.MAX_VALUE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a listener that will be called whenever any property on the animated object is updated.
|
* Adds a listener that will be called whenever any property on the animated object is updated.
|
||||||
* This will be called on every animation frame, with the current value of the animated object
|
* This will be called on every animation frame, with the current value of the animated object
|
||||||
|
|||||||
Reference in New Issue
Block a user