Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd36bac2 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

Update screenshot animation from Overview

When invoked from Overview, the screenshot ended up at the wrong
size (since the input bitmap is a different size, coming from the
Recents screenshot). Changing the scale to start at the size of the
input bitmap (as well as starting at the correct location) fixes
this problem.

Bug: 155415994
Fix:155415994
Test: manual; tested from Overview and from chord invocation

Change-Id: I25f2ff982af75ea36da7b3e8e47f93c720101b97
parent 906f8000
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -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() {