From ce7918275ed052332b7e97ee43f6dd7a90a778a3 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Fri, 23 Oct 2020 11:28:24 -0400 Subject: [PATCH] Remove screenshot animated view Simplifies the layout/animation code of the screenshots UI by removing the "screenshot_animated_view" and instead just animating the preview from the starting point to its static location. This change supports the swipe-dismiss change by making the underlying views easier to work with. Bug: 157223526 Test: manual; tested from keychord and overview to ensure no visual change Change-Id: I52525aaa0743c5b15f515a50aa79f8dfb547fdff --- .../SystemUI/res/layout/global_screenshot.xml | 8 -- .../screenshot/ScreenshotController.java | 2 +- .../systemui/screenshot/ScreenshotView.java | 81 ++++++------------- 3 files changed, 24 insertions(+), 67 deletions(-) diff --git a/packages/SystemUI/res/layout/global_screenshot.xml b/packages/SystemUI/res/layout/global_screenshot.xml index e0333eb82d518..1b5f9c1ced8fb 100644 --- a/packages/SystemUI/res/layout/global_screenshot.xml +++ b/packages/SystemUI/res/layout/global_screenshot.xml @@ -26,14 +26,6 @@ android:layout_gravity="bottom" android:alpha="0.0" android:src="@drawable/screenshot_actions_background_protection"/> - mSmartChips = new ArrayList<>(); + private final ArrayList mSmartChips = new ArrayList<>(); private PendingInteraction mPendingInteraction; private enum PendingInteraction { @@ -183,8 +181,6 @@ public class ScreenshotView extends FrameLayout implements @Override // View protected void onFinishInflate() { - mScreenshotAnimatedView = requireNonNull( - findViewById(R.id.global_screenshot_animated_view)); mScreenshotPreview = requireNonNull(findViewById(R.id.global_screenshot_preview)); mActionsContainerBackground = requireNonNull(findViewById( R.id.global_screenshot_actions_container_background)); @@ -198,14 +194,6 @@ public class ScreenshotView extends FrameLayout implements mShareChip = requireNonNull(mActionsContainer.findViewById(R.id.screenshot_share_chip)); mEditChip = requireNonNull(mActionsContainer.findViewById(R.id.screenshot_edit_chip)); - mScreenshotAnimatedView.setClipToOutline(true); - mScreenshotAnimatedView.setOutlineProvider(new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - outline.setRoundRect(new Rect(0, 0, view.getWidth(), view.getHeight()), - ROUNDED_CORNER_RADIUS * view.getWidth()); - } - }); mScreenshotPreview.setClipToOutline(true); mScreenshotPreview.setOutlineProvider(new ViewOutlineProvider() { @Override @@ -218,8 +206,6 @@ public class ScreenshotView extends FrameLayout implements setFocusable(true); mScreenshotSelectorView.setFocusable(true); mScreenshotSelectorView.setFocusableInTouchMode(true); - mScreenshotAnimatedView.setPivotX(0); - mScreenshotAnimatedView.setPivotY(0); mActionsContainer.setScrollX(0); mNavMode = getResources().getInteger( @@ -253,13 +239,6 @@ public class ScreenshotView extends FrameLayout implements } void prepareForAnimation(Bitmap bitmap, Rect screenRect, Insets screenInsets) { - mScreenshotAnimatedView.setImageDrawable( - createScreenDrawable(mResources, bitmap, screenInsets)); - setAnimatedViewSize(screenRect.width(), screenRect.height()); - - // will show when the animation starts - mScreenshotAnimatedView.setVisibility(View.GONE); - mScreenshotPreview.setImageDrawable(createScreenDrawable(mResources, bitmap, screenInsets)); // make static preview invisible (from gone) so we can query its location on screen mScreenshotPreview.setVisibility(View.INVISIBLE); @@ -275,10 +254,10 @@ public class ScreenshotView extends FrameLayout implements float cornerScale = mCornerSizeX / (mOrientationPortrait ? bounds.width() : bounds.height()); - final float currentScale = 1f; + final float currentScale = 1 / cornerScale; - mScreenshotAnimatedView.setScaleX(currentScale); - mScreenshotAnimatedView.setScaleY(currentScale); + mScreenshotPreview.setScaleX(currentScale); + mScreenshotPreview.setScaleY(currentScale); mDismissButton.setAlpha(0); mDismissButton.setVisibility(View.VISIBLE); @@ -312,36 +291,33 @@ public class ScreenshotView extends FrameLayout implements float t = animation.getAnimatedFraction(); if (t < scalePct) { float scale = MathUtils.lerp( - currentScale, cornerScale, mFastOutSlowIn.getInterpolation(t / scalePct)); - mScreenshotAnimatedView.setScaleX(scale); - mScreenshotAnimatedView.setScaleY(scale); + currentScale, 1, mFastOutSlowIn.getInterpolation(t / scalePct)); + mScreenshotPreview.setScaleX(scale); + mScreenshotPreview.setScaleY(scale); } else { - mScreenshotAnimatedView.setScaleX(cornerScale); - mScreenshotAnimatedView.setScaleY(cornerScale); + mScreenshotPreview.setScaleX(1); + mScreenshotPreview.setScaleY(1); } - float currentScaleX = mScreenshotAnimatedView.getScaleX(); - float currentScaleY = mScreenshotAnimatedView.getScaleY(); - if (t < xPositionPct) { float xCenter = MathUtils.lerp(startPos.x, finalPos.x, mFastOutSlowIn.getInterpolation(t / xPositionPct)); - mScreenshotAnimatedView.setX(xCenter - bounds.width() * currentScaleX / 2f); + mScreenshotPreview.setX(xCenter - mScreenshotPreview.getWidth() / 2f); } else { - mScreenshotAnimatedView.setX(finalPos.x - bounds.width() * currentScaleX / 2f); + mScreenshotPreview.setX(finalPos.x - mScreenshotPreview.getWidth() / 2f); } float yCenter = MathUtils.lerp( startPos.y, finalPos.y, mFastOutSlowIn.getInterpolation(t)); - mScreenshotAnimatedView.setY(yCenter - bounds.height() * currentScaleY / 2f); + mScreenshotPreview.setY(yCenter - mScreenshotPreview.getHeight() / 2f); if (t >= dismissPct) { mDismissButton.setAlpha((t - dismissPct) / (1 - dismissPct)); - float currentX = mScreenshotAnimatedView.getX(); - float currentY = mScreenshotAnimatedView.getY(); + float currentX = mScreenshotPreview.getX(); + float currentY = mScreenshotPreview.getY(); mDismissButton.setY(currentY - mDismissButton.getHeight() / 2f); if (mDirectionLTR) { - mDismissButton.setX(currentX - + bounds.width() * currentScaleX - mDismissButton.getWidth() / 2f); + mDismissButton.setX(currentX + mScreenshotPreview.getWidth() + - mDismissButton.getWidth() / 2f); } else { mDismissButton.setX(currentX - mDismissButton.getWidth() / 2f); } @@ -352,7 +328,7 @@ public class ScreenshotView extends FrameLayout implements @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); - mScreenshotAnimatedView.setVisibility(View.VISIBLE); + mScreenshotPreview.setVisibility(View.VISIBLE); } }); @@ -380,13 +356,11 @@ public class ScreenshotView extends FrameLayout implements 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); - forceLayout(); + mScreenshotPreview.setScaleX(1); + mScreenshotPreview.setScaleY(1); + mScreenshotPreview.setX(finalPos.x - bounds.width() * cornerScale / 2f); + mScreenshotPreview.setY(finalPos.y - bounds.height() * cornerScale / 2f); + requestLayout(); createScreenshotActionsShadeAnimation().start(); } }); @@ -540,8 +514,6 @@ public class ScreenshotView extends FrameLayout implements void reset() { // Clear any references to the bitmap mScreenshotPreview.setImageDrawable(null); - mScreenshotAnimatedView.setImageDrawable(null); - mScreenshotAnimatedView.setVisibility(View.GONE); mActionsContainerBackground.setVisibility(View.GONE); mActionsContainer.setVisibility(View.GONE); mBackgroundProtection.setAlpha(0f); @@ -568,13 +540,6 @@ public class ScreenshotView extends FrameLayout implements mScreenshotSelectorView.stop(); } - private void setAnimatedViewSize(int width, int height) { - ViewGroup.LayoutParams layoutParams = mScreenshotAnimatedView.getLayoutParams(); - layoutParams.width = width; - layoutParams.height = height; - mScreenshotAnimatedView.setLayoutParams(layoutParams); - } - /** * Create a drawable using the size of the bitmap and insets as the fractional inset parameters. */