From 958eb9dcd5c3096e3ce6e109e97682d74c835a52 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Tue, 9 Jun 2020 15:12:44 -0400 Subject: [PATCH] Animate screenshot dismiss button appearance Currently the dismiss button just pops in once the animation is complete, which is somewhat jarring (and because the animation decelerates as it ends, it feels like there's a delay before the button actually appears). This change starts fading in the button while the animation is happening, matching its location to the preview at each animation update. Bug: 155415756 Fix: 155415756 Test: manual -- tested with ltr/rtl, portrait/landscape, and from overview vs keychord, all looked correct Change-Id: Ibd3ea2a4127d6fee87ec9b73d73f8f5a184d1417 --- .../SystemUI/res/layout/global_screenshot.xml | 14 +++++++++ .../res/layout/global_screenshot_static.xml | 18 ------------ .../systemui/screenshot/GlobalScreenshot.java | 29 ++++++++++++++++++- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/SystemUI/res/layout/global_screenshot.xml b/packages/SystemUI/res/layout/global_screenshot.xml index 6a235218b32ff..ef7325ea8f380 100644 --- a/packages/SystemUI/res/layout/global_screenshot.xml +++ b/packages/SystemUI/res/layout/global_screenshot.xml @@ -48,4 +48,18 @@ android:visibility="gone" android:pointerIcon="crosshair"/> + + + diff --git a/packages/SystemUI/res/layout/global_screenshot_static.xml b/packages/SystemUI/res/layout/global_screenshot_static.xml index da5277ce3876c..9ec2f20597e7b 100644 --- a/packages/SystemUI/res/layout/global_screenshot_static.xml +++ b/packages/SystemUI/res/layout/global_screenshot_static.xml @@ -54,22 +54,4 @@ android:layout_height="wrap_content"/> - - - diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 57436bc9e6756..d09fdaf704e05 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -174,6 +174,8 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset private static final long SCREENSHOT_FLASH_IN_DURATION_MS = 133; private static final long SCREENSHOT_FLASH_OUT_DURATION_MS = 217; + // delay before starting to fade in dismiss button + private static final long SCREENSHOT_TO_CORNER_DISMISS_DELAY_MS = 200; private static final long SCREENSHOT_TO_CORNER_X_DURATION_MS = 234; private static final long SCREENSHOT_TO_CORNER_Y_DURATION_MS = 500; private static final long SCREENSHOT_TO_CORNER_SCALE_DURATION_MS = 234; @@ -773,6 +775,9 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset mScreenshotAnimatedView.setScaleX(currentScale); mScreenshotAnimatedView.setScaleY(currentScale); + mDismissButton.setAlpha(0); + mDismissButton.setVisibility(View.VISIBLE); + AnimatorSet dropInAnimation = new AnimatorSet(); ValueAnimator flashInAnimator = ValueAnimator.ofFloat(0, 1); flashInAnimator.setDuration(SCREENSHOT_FLASH_IN_DURATION_MS); @@ -794,6 +799,8 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset toCorner.setDuration(SCREENSHOT_TO_CORNER_Y_DURATION_MS); float xPositionPct = SCREENSHOT_TO_CORNER_X_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS; + float dismissPct = + SCREENSHOT_TO_CORNER_DISMISS_DELAY_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS; float scalePct = SCREENSHOT_TO_CORNER_SCALE_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS; toCorner.addUpdateListener(animation -> { @@ -821,6 +828,19 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset float yCenter = MathUtils.lerp( startPos.y, finalPos.y, mFastOutSlowIn.getInterpolation(t)); mScreenshotAnimatedView.setY(yCenter - bounds.height() * currentScaleY / 2f); + + if (t >= dismissPct) { + mDismissButton.setAlpha((t - dismissPct) / (1 - dismissPct)); + float currentX = mScreenshotAnimatedView.getX(); + float currentY = mScreenshotAnimatedView.getY(); + mDismissButton.setY(currentY - mDismissButton.getHeight() / 2f); + if (mDirectionLTR) { + mDismissButton.setX(currentX + + bounds.width() * currentScaleX - mDismissButton.getWidth() / 2f); + } else { + mDismissButton.setX(currentX - mDismissButton.getWidth() / 2f); + } + } }); toCorner.addListener(new AnimatorListenerAdapter() { @@ -845,13 +865,20 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); + mDismissButton.setAlpha(1); + float dismissOffset = mDismissButton.getWidth() / 2f; + float finalDismissX = mDirectionLTR + ? finalPos.x - dismissOffset + bounds.width() * cornerScale / 2f + : finalPos.x - dismissOffset - bounds.width() * cornerScale / 2f; + mDismissButton.setX(finalDismissX); + mDismissButton.setY( + finalPos.y - dismissOffset - bounds.height() * cornerScale / 2f); mScreenshotAnimatedView.setScaleX(1); mScreenshotAnimatedView.setScaleY(1); mScreenshotAnimatedView.setX(finalPos.x - bounds.width() * cornerScale / 2f); mScreenshotAnimatedView.setY(finalPos.y - bounds.height() * cornerScale / 2f); mScreenshotAnimatedView.setVisibility(View.GONE); mScreenshotPreview.setVisibility(View.VISIBLE); - mDismissButton.setVisibility(View.VISIBLE); mScreenshotLayout.forceLayout(); } });