From a083d73f872d59ccf60832925c76e6dee6661d7a Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Tue, 21 Apr 2020 15:21:39 -0400 Subject: [PATCH] Fix screenshot UI entrance animation Makes the actions container expand out horizontally, rather than coming up from the bottom. Test: manual Fixes: 153725541 Change-Id: I9485ed1ca23fb18b12e3994fa61a9e07a55d2ce1 --- .../SystemUI/res/layout/global_screenshot.xml | 1 + .../layout/global_screenshot_action_chip.xml | 17 +++++------ .../systemui/screenshot/GlobalScreenshot.java | 28 +++++++++++++++---- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/packages/SystemUI/res/layout/global_screenshot.xml b/packages/SystemUI/res/layout/global_screenshot.xml index db109fe8a5411..94a6bc566e73e 100644 --- a/packages/SystemUI/res/layout/global_screenshot.xml +++ b/packages/SystemUI/res/layout/global_screenshot.xml @@ -38,6 +38,7 @@ android:elevation="1dp" android:fillViewport="true" android:layout_marginHorizontal="@dimen/screenshot_action_container_margin_horizontal" + android:layout_marginBottom="@dimen/screenshot_action_container_offset_y" android:gravity="center" android:paddingLeft="@dimen/screenshot_action_container_padding_left" android:paddingRight="@dimen/screenshot_action_container_padding_right" diff --git a/packages/SystemUI/res/layout/global_screenshot_action_chip.xml b/packages/SystemUI/res/layout/global_screenshot_action_chip.xml index 6b94befad0f8a..bd91ddb5f406a 100644 --- a/packages/SystemUI/res/layout/global_screenshot_action_chip.xml +++ b/packages/SystemUI/res/layout/global_screenshot_action_chip.xml @@ -16,14 +16,15 @@ --> + android:id="@+id/global_screenshot_action_chip" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginRight="@dimen/screenshot_action_chip_margin_right" + android:layout_gravity="center" + android:paddingVertical="@dimen/screenshot_action_chip_padding_vertical" + android:background="@drawable/action_chip_background" + android:alpha="0" + android:gravity="center"> chips = new ArrayList<>(); + for (Notification.Action smartAction : imageData.smartActions) { ScreenshotActionChip actionChip = (ScreenshotActionChip) inflater.inflate( R.layout.global_screenshot_action_chip, mActionsView, false); @@ -662,6 +669,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset clearScreenshot("chip tapped"); }); mActionsView.addView(actionChip); + chips.add(actionChip); } ScreenshotActionChip shareChip = (ScreenshotActionChip) inflater.inflate( @@ -673,6 +681,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset clearScreenshot("chip tapped"); }); mActionsView.addView(shareChip); + chips.add(shareChip); ScreenshotActionChip editChip = (ScreenshotActionChip) inflater.inflate( R.layout.global_screenshot_action_chip, mActionsView, false); @@ -683,6 +692,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset clearScreenshot("chip tapped"); }); mActionsView.addView(editChip); + chips.add(editChip); mScreenshotView.setOnClickListener(v -> { try { @@ -695,7 +705,6 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset }); mScreenshotView.setContentDescription(imageData.editAction.title); - if (DeviceConfig.getBoolean(NAMESPACE_SYSTEMUI, SCREENSHOT_SCROLLING_ENABLED, false)) { ScreenshotActionChip scrollChip = (ScreenshotActionChip) inflater.inflate( R.layout.global_screenshot_action_chip, mActionsView, false); @@ -709,18 +718,27 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset scrollNotImplemented.show(); }); mActionsView.addView(scrollChip); + chips.add(scrollChip); } ValueAnimator animator = ValueAnimator.ofFloat(0, 1); - mActionsContainer.setY(mDisplayMetrics.heightPixels); + animator.setDuration(SCREENSHOT_ACTIONS_EXPANSION_DURATION_MS); + float alphaFraction = (float) SCREENSHOT_ACTIONS_ALPHA_DURATION_MS + / SCREENSHOT_ACTIONS_EXPANSION_DURATION_MS; mActionsContainer.setVisibility(VISIBLE); - mActionsContainer.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - float actionsViewHeight = mActionsContainer.getMeasuredHeight() + mScreenshotHeightPx; + mActionsContainer.setAlpha(0); animator.addUpdateListener(animation -> { float t = animation.getAnimatedFraction(); mBackgroundProtection.setAlpha(t); - mActionsContainer.setY(mDisplayMetrics.heightPixels - actionsViewHeight * t); + mActionsContainer.setAlpha(t < alphaFraction ? t / alphaFraction : 1); + float containerScale = SCREENSHOT_ACTIONS_START_SCALE_X + + (t * (1 - SCREENSHOT_ACTIONS_START_SCALE_X)); + mActionsContainer.setScaleX(containerScale); + for (ScreenshotActionChip chip : chips) { + chip.setAlpha(t); + chip.setScaleX(1 / containerScale); // invert to keep size of children constant + } }); return animator; }