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
This commit is contained in:
Miranda Kephart
2020-06-09 15:12:44 -04:00
parent 6097e16b38
commit 958eb9dcd5
3 changed files with 42 additions and 19 deletions

View File

@@ -48,4 +48,18 @@
android:visibility="gone"
android:pointerIcon="crosshair"/>
<include layout="@layout/global_screenshot_static"/>
<FrameLayout
android:id="@+id/global_screenshot_dismiss_button"
android:layout_width="@dimen/screenshot_dismiss_button_tappable_size"
android:layout_height="@dimen/screenshot_dismiss_button_tappable_size"
android:elevation="7dp"
android:visibility="gone"
android:contentDescription="@string/screenshot_dismiss_ui_description">
<ImageView
android:id="@+id/global_screenshot_dismiss_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/screenshot_dismiss_button_margin"
android:src="@drawable/screenshot_cancel"/>
</FrameLayout>
</FrameLayout>

View File

@@ -54,22 +54,4 @@
android:layout_height="wrap_content"/>
</HorizontalScrollView>
<include layout="@layout/global_screenshot_preview"/>
<FrameLayout
android:id="@+id/global_screenshot_dismiss_button"
android:layout_width="@dimen/screenshot_dismiss_button_tappable_size"
android:layout_height="@dimen/screenshot_dismiss_button_tappable_size"
android:elevation="7dp"
android:visibility="gone"
android:contentDescription="@string/screenshot_dismiss_ui_description"
app:layout_constraintStart_toEndOf="@+id/global_screenshot_preview"
app:layout_constraintEnd_toEndOf="@+id/global_screenshot_preview"
app:layout_constraintTop_toTopOf="@+id/global_screenshot_preview"
app:layout_constraintBottom_toTopOf="@+id/global_screenshot_preview">
<ImageView
android:id="@+id/global_screenshot_dismiss_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/screenshot_dismiss_button_margin"
android:src="@drawable/screenshot_cancel"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -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();
}
});