Fix screenshot scaling bug

Occasionally, the screenshot preview would not reach the correct
final scale, instead getting "stuck" at some larger size. This is
because there was no final condition for the scale, so the final
state depended on exactly which values the ValueAnimator update
listener was called with. Setting a final state correctly fixes
this problem.

(Also fixes the equivalent bug for the x position.)

Bug: 150134649
Test: manual -- there was not a reliable repro for the bug, but it
hasn't been seen since making the change

Change-Id: Ia383ca9336db382fd54087ce12accafd35b48a22
This commit is contained in:
Miranda Kephart
2020-02-24 13:12:41 -05:00
parent 14ebab3b19
commit 2750ad0d59

View File

@@ -514,12 +514,17 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
1, cornerScale, mFastOutSlowIn.getInterpolation(t / scalePct));
mScreenshotView.setScaleX(scale);
mScreenshotView.setScaleY(scale);
} else {
mScreenshotView.setScaleX(cornerScale);
mScreenshotView.setScaleY(cornerScale);
}
if (t < xPositionPct) {
float xCenter = MathUtils.lerp(startPos.x, finalPos.x,
mFastOutSlowIn.getInterpolation(t / xPositionPct));
mScreenshotView.setX(xCenter - width * mScreenshotView.getScaleX() / 2f);
} else {
mScreenshotView.setX(finalPos.x - width * mScreenshotView.getScaleX() / 2f);
}
float yCenter = MathUtils.lerp(startPos.y, finalPos.y,
mFastOutSlowIn.getInterpolation(t));
@@ -544,6 +549,10 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mScreenshotView.setScaleX(cornerScale);
mScreenshotView.setScaleY(cornerScale);
mScreenshotView.setX(finalPos.x - height * cornerScale / 2f);
mScreenshotView.setY(finalPos.y - height * cornerScale / 2f);
Rect bounds = new Rect();
mScreenshotView.getBoundsOnScreen(bounds);
mDismissButton.setX(bounds.right - mDismissButtonSize / 2f);