Merge "Update screenshot animation from Overview" into rvc-dev

This commit is contained in:
Miranda Kephart
2020-05-18 18:02:07 +00:00
committed by Android (Google) Code Review

View File

@@ -642,13 +642,10 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
private void startAnimation(final Consumer<Uri> finisher, int w, int h,
@Nullable Rect screenRect) {
// If power save is on, show a toast so there is some visual indication that a
// screenshot
// has been taken.
PowerManager powerManager = (PowerManager) mContext.getSystemService(
Context.POWER_SERVICE);
// screenshot has been taken.
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
if (powerManager.isPowerSaveMode()) {
Toast.makeText(mContext, R.string.screenshot_saved_title,
Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show();
}
mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect);
@@ -712,18 +709,23 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
}
private AnimatorSet createScreenshotDropInAnimation(int width, int height, Rect bounds) {
float screenWidth = mDisplayMetrics.widthPixels;
float screenHeight = mDisplayMetrics.heightPixels;
int rotation = mContext.getDisplay().getRotation();
float cornerScale;
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
cornerScale = (mCornerSizeX / (float) height);
cornerScale = (mCornerSizeX / screenHeight);
} else {
cornerScale = (mCornerSizeX / (float) width);
cornerScale = (mCornerSizeX / screenWidth);
}
float currentScale = width / screenWidth;
mScreenshotAnimatedView.setScaleX(1);
mScreenshotAnimatedView.setScaleY(1);
mScreenshotAnimatedView.setX(0);
mScreenshotAnimatedView.setY(0);
mScreenshotAnimatedView.setScaleX(currentScale);
mScreenshotAnimatedView.setScaleY(currentScale);
mScreenshotAnimatedView.setPivotX(0);
mScreenshotAnimatedView.setPivotY(0);
mScreenshotAnimatedView.setImageBitmap(mScreenBitmap);
mScreenshotPreview.setImageBitmap(mScreenBitmap);
@@ -744,12 +746,11 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
final PointF startPos = new PointF(bounds.centerX(), bounds.centerY());
float finalX;
if (mDirectionLTR) {
finalX = mScreenshotOffsetXPx + width * cornerScale / 2f;
finalX = mScreenshotOffsetXPx + screenWidth * cornerScale / 2f;
} else {
finalX = width - mScreenshotOffsetXPx - width * cornerScale / 2f;
finalX = screenWidth - mScreenshotOffsetXPx - screenWidth * cornerScale / 2f;
}
float finalY =
mDisplayMetrics.heightPixels - mScreenshotOffsetYPx - height * cornerScale / 2f;
float finalY = screenHeight - mScreenshotOffsetYPx - screenHeight * cornerScale / 2f;
final PointF finalPos = new PointF(finalX, finalY);
ValueAnimator toCorner = ValueAnimator.ofFloat(0, 1);
@@ -757,13 +758,12 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
float xPositionPct =
SCREENSHOT_TO_CORNER_X_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS;
float scalePct =
SCREENSHOT_TO_CORNER_SCALE_DURATION_MS
/ (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS;
SCREENSHOT_TO_CORNER_SCALE_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS;
toCorner.addUpdateListener(animation -> {
float t = animation.getAnimatedFraction();
if (t < scalePct) {
float scale = MathUtils.lerp(
1, cornerScale, mFastOutSlowIn.getInterpolation(t / scalePct));
currentScale, cornerScale, mFastOutSlowIn.getInterpolation(t / scalePct));
mScreenshotAnimatedView.setScaleX(scale);
mScreenshotAnimatedView.setScaleY(scale);
} else {
@@ -777,13 +777,13 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
if (t < xPositionPct) {
float xCenter = MathUtils.lerp(startPos.x, finalPos.x,
mFastOutSlowIn.getInterpolation(t / xPositionPct));
mScreenshotAnimatedView.setX(xCenter - width * currentScaleX / 2f);
mScreenshotAnimatedView.setX(xCenter - screenWidth * currentScaleX / 2f);
} else {
mScreenshotAnimatedView.setX(finalPos.x - width * currentScaleX / 2f);
mScreenshotAnimatedView.setX(finalPos.x - screenWidth * currentScaleX / 2f);
}
float yCenter = MathUtils.lerp(startPos.y, finalPos.y,
mFastOutSlowIn.getInterpolation(t));
mScreenshotAnimatedView.setY(yCenter - height * currentScaleY / 2f);
mScreenshotAnimatedView.setY(yCenter - screenHeight * currentScaleY / 2f);
});
toCorner.addListener(new AnimatorListenerAdapter() {