diff options
| author | 2021-06-29 09:30:54 -0400 | |
|---|---|---|
| committer | 2021-06-29 09:56:33 -0400 | |
| commit | 9c759448ee1ac9062c0e953db593a08c742a9bf0 (patch) | |
| tree | 3e084f5f0e8e9e444d658ee6190e69844c5e59c6 | |
| parent | 87d84d5e234bb5ef945116f7d502359d5520208c (diff) | |
Turn off screenshot transition into long screenshots for rotations
If the user rotates the phone between the initial screenshot capture
and the long screenshot capture, the views will be completely
different and it doesn't make sense to try to transition from the
preview into the long screenshots activity.
This change just turns off the preview transition for this case
(though we still show the scrim and fade it out during the
transition).
Bug: 192344739
Fix: 192344739
Test: manual
Change-Id: I5951c074ad8ddb3957a76df963979cf47c987a66
3 files changed, 93 insertions, 54 deletions
diff --git a/packages/SystemUI/res/layout/global_screenshot_static.xml b/packages/SystemUI/res/layout/global_screenshot_static.xml index ba46edced03c..665d4a04b00b 100644 --- a/packages/SystemUI/res/layout/global_screenshot_static.xml +++ b/packages/SystemUI/res/layout/global_screenshot_static.xml @@ -127,6 +127,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="matrix" + android:visibility="gone" app:layout_constraintStart_toStartOf="@id/global_screenshot_preview" app:layout_constraintTop_toTopOf="@id/global_screenshot_preview" android:elevation="@dimen/screenshot_preview_elevation"/> diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 24cca91ea3f3..0dbe568b0a2d 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -16,6 +16,7 @@ package com.android.systemui.screenshot; +import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT; @@ -257,6 +258,7 @@ public class ScreenshotController { private ScreenshotView mScreenshotView; private Bitmap mScreenBitmap; private SaveImageInBackgroundTask mSaveInBgTask; + private boolean mScreenshotTakenInPortrait; private Animator mScreenshotAnimation; private RequestCallback mCurrentRequestCallback; @@ -484,6 +486,9 @@ public class ScreenshotController { * Takes a screenshot of the current display and shows an animation. */ private void takeScreenshotInternal(Consumer<Uri> finisher, Rect crop) { + mScreenshotTakenInPortrait = + mContext.getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT; + // copy the input Rect, since SurfaceControl.screenshot can mutate it Rect screenRect = new Rect(crop); Bitmap screenshot = captureScreenshot(crop); @@ -653,7 +658,8 @@ public class ScreenshotController { Bitmap newScreenshot = captureScreenshot( new Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels)); - mScreenshotView.prepareScrollingTransition(response, mScreenBitmap, newScreenshot); + mScreenshotView.prepareScrollingTransition(response, mScreenBitmap, newScreenshot, + mScreenshotTakenInPortrait); // delay starting scroll capture to make sure the scrim is up before the app moves mScreenshotView.post(() -> { // Clear the reference to prevent close() in dismissScreenshot diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java index 9fe8c84bc13d..dc736374cd59 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java @@ -162,6 +162,7 @@ public class ScreenshotView extends FrameLayout implements private GestureDetector mSwipeDetector; private SwipeDismissHandler mSwipeDismissHandler; private InputMonitorCompat mInputMonitor; + private boolean mShowScrollablePreview; private final ArrayList<ScreenshotActionChip> mSmartChips = new ArrayList<>(); private PendingInteraction mPendingInteraction; @@ -772,70 +773,99 @@ public class ScreenshotView extends FrameLayout implements void startLongScreenshotTransition(Rect destination, Runnable onTransitionEnd, ScrollCaptureController.LongScreenshot longScreenshot) { - mScrollablePreview.setImageBitmap(longScreenshot.toBitmap()); - ValueAnimator anim = ValueAnimator.ofFloat(0, 1); - float startX = mScrollablePreview.getX(); - float startY = mScrollablePreview.getY(); - int[] locInScreen = mScrollablePreview.getLocationOnScreen(); - destination.offset((int) startX - locInScreen[0], (int) startY - locInScreen[1]); - mScrollablePreview.setPivotX(0); - mScrollablePreview.setPivotY(0); - mScrollablePreview.setAlpha(1f); - float currentScale = mScrollablePreview.getWidth() / (float) longScreenshot.getWidth(); - Matrix matrix = new Matrix(); - matrix.setScale(currentScale, currentScale); - matrix.postTranslate( - longScreenshot.getLeft() * currentScale, longScreenshot.getTop() * currentScale); - mScrollablePreview.setImageMatrix(matrix); - float destinationScale = destination.width() / (float) mScrollablePreview.getWidth(); - anim.addUpdateListener(animation -> { - float t = animation.getAnimatedFraction(); - mScrollingScrim.setAlpha(1 - t); - float currScale = MathUtils.lerp(1, destinationScale, t); - mScrollablePreview.setScaleX(currScale); - mScrollablePreview.setScaleY(currScale); - mScrollablePreview.setX(MathUtils.lerp(startX, destination.left, t)); - mScrollablePreview.setY(MathUtils.lerp(startY, destination.top, t)); - }); - anim.addListener(new AnimatorListenerAdapter() { + AnimatorSet animSet = new AnimatorSet(); + + ValueAnimator scrimAnim = ValueAnimator.ofFloat(0, 1); + scrimAnim.addUpdateListener(animation -> + mScrollingScrim.setAlpha(1 - animation.getAnimatedFraction())); + + if (mShowScrollablePreview) { + mScrollablePreview.setImageBitmap(longScreenshot.toBitmap()); + float startX = mScrollablePreview.getX(); + float startY = mScrollablePreview.getY(); + int[] locInScreen = mScrollablePreview.getLocationOnScreen(); + destination.offset((int) startX - locInScreen[0], (int) startY - locInScreen[1]); + mScrollablePreview.setPivotX(0); + mScrollablePreview.setPivotY(0); + mScrollablePreview.setAlpha(1f); + float currentScale = mScrollablePreview.getWidth() / (float) longScreenshot.getWidth(); + Matrix matrix = new Matrix(); + matrix.setScale(currentScale, currentScale); + matrix.postTranslate( + longScreenshot.getLeft() * currentScale, + longScreenshot.getTop() * currentScale); + mScrollablePreview.setImageMatrix(matrix); + float destinationScale = destination.width() / (float) mScrollablePreview.getWidth(); + + ValueAnimator previewAnim = ValueAnimator.ofFloat(0, 1); + previewAnim.addUpdateListener(animation -> { + float t = animation.getAnimatedFraction(); + float currScale = MathUtils.lerp(1, destinationScale, t); + mScrollablePreview.setScaleX(currScale); + mScrollablePreview.setScaleY(currScale); + mScrollablePreview.setX(MathUtils.lerp(startX, destination.left, t)); + mScrollablePreview.setY(MathUtils.lerp(startY, destination.top, t)); + }); + ValueAnimator previewFadeAnim = ValueAnimator.ofFloat(1, 0); + previewFadeAnim.addUpdateListener(animation -> + mScrollablePreview.setAlpha(1 - animation.getAnimatedFraction())); + animSet.play(previewAnim).with(scrimAnim).before(previewFadeAnim); + previewAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + onTransitionEnd.run(); + } + }); + } else { + // if we switched orientations between the original screenshot and the long screenshot + // capture, just fade out the scrim instead of running the preview animation + animSet.play(scrimAnim); + animSet.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + onTransitionEnd.run(); + } + }); + } + animSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); - onTransitionEnd.run(); - mScrollablePreview.animate().alpha(0).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); mCallbacks.onDismiss(); } - }); - } }); - anim.start(); + animSet.start(); } void prepareScrollingTransition(ScrollCaptureResponse response, Bitmap screenBitmap, - Bitmap newBitmap) { + Bitmap newBitmap, boolean screenshotTakenInPortrait) { + mShowScrollablePreview = (screenshotTakenInPortrait == mOrientationPortrait); + mScrollingScrim.setImageBitmap(newBitmap); mScrollingScrim.setVisibility(View.VISIBLE); - Rect scrollableArea = scrollableAreaOnScreen(response); - float scale = mCornerSizeX - / (mOrientationPortrait ? screenBitmap.getWidth() : screenBitmap.getHeight()); - ConstraintLayout.LayoutParams params = - (ConstraintLayout.LayoutParams) mScrollablePreview.getLayoutParams(); - - params.width = (int) (scale * scrollableArea.width()); - params.height = (int) (scale * scrollableArea.height()); - Matrix matrix = new Matrix(); - matrix.setScale(scale, scale); - matrix.postTranslate(-scrollableArea.left * scale, -scrollableArea.top * scale); - - mScrollablePreview.setTranslationX(scale * scrollableArea.left); - mScrollablePreview.setTranslationY(scale * scrollableArea.top); - mScrollablePreview.setImageMatrix(matrix); - - mScrollablePreview.setImageBitmap(screenBitmap); - mScrollablePreview.setVisibility(View.VISIBLE); + + if (mShowScrollablePreview) { + Rect scrollableArea = scrollableAreaOnScreen(response); + + float scale = mCornerSizeX + / (mOrientationPortrait ? screenBitmap.getWidth() : screenBitmap.getHeight()); + ConstraintLayout.LayoutParams params = + (ConstraintLayout.LayoutParams) mScrollablePreview.getLayoutParams(); + + params.width = (int) (scale * scrollableArea.width()); + params.height = (int) (scale * scrollableArea.height()); + Matrix matrix = new Matrix(); + matrix.setScale(scale, scale); + matrix.postTranslate(-scrollableArea.left * scale, -scrollableArea.top * scale); + + mScrollablePreview.setTranslationX(scale * scrollableArea.left); + mScrollablePreview.setTranslationY(scale * scrollableArea.top); + mScrollablePreview.setImageMatrix(matrix); + mScrollablePreview.setImageBitmap(screenBitmap); + mScrollablePreview.setVisibility(View.VISIBLE); + } mDismissButton.setVisibility(View.GONE); mActionsContainer.setVisibility(View.GONE); mBackgroundProtection.setVisibility(View.GONE); @@ -919,6 +949,8 @@ public class ScreenshotView extends FrameLayout implements mActionsContainer.setVisibility(View.GONE); mBackgroundProtection.setAlpha(0f); mDismissButton.setVisibility(View.GONE); + mScrollingScrim.setVisibility(View.GONE); + mScrollablePreview.setVisibility(View.GONE); mScreenshotStatic.setTranslationX(0); mScreenshotPreview.setTranslationY(0); mScreenshotPreview.setContentDescription( |