Merge "Turn off screenshot transition into long screenshots for rotations" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
aa1b081a72
@@ -127,6 +127,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:scaleType="matrix"
|
android:scaleType="matrix"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintStart_toStartOf="@id/global_screenshot_preview"
|
app:layout_constraintStart_toStartOf="@id/global_screenshot_preview"
|
||||||
app:layout_constraintTop_toTopOf="@id/global_screenshot_preview"
|
app:layout_constraintTop_toTopOf="@id/global_screenshot_preview"
|
||||||
android:elevation="@dimen/screenshot_preview_elevation"/>
|
android:elevation="@dimen/screenshot_preview_elevation"/>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.systemui.screenshot;
|
package com.android.systemui.screenshot;
|
||||||
|
|
||||||
|
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
||||||
import static android.view.Display.DEFAULT_DISPLAY;
|
import static android.view.Display.DEFAULT_DISPLAY;
|
||||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
|
import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;
|
||||||
@@ -259,6 +260,7 @@ public class ScreenshotController {
|
|||||||
private ScreenshotView mScreenshotView;
|
private ScreenshotView mScreenshotView;
|
||||||
private Bitmap mScreenBitmap;
|
private Bitmap mScreenBitmap;
|
||||||
private SaveImageInBackgroundTask mSaveInBgTask;
|
private SaveImageInBackgroundTask mSaveInBgTask;
|
||||||
|
private boolean mScreenshotTakenInPortrait;
|
||||||
|
|
||||||
private Animator mScreenshotAnimation;
|
private Animator mScreenshotAnimation;
|
||||||
private RequestCallback mCurrentRequestCallback;
|
private RequestCallback mCurrentRequestCallback;
|
||||||
@@ -488,6 +490,9 @@ public class ScreenshotController {
|
|||||||
* Takes a screenshot of the current display and shows an animation.
|
* Takes a screenshot of the current display and shows an animation.
|
||||||
*/
|
*/
|
||||||
private void takeScreenshotInternal(Consumer<Uri> finisher, Rect crop) {
|
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
|
// copy the input Rect, since SurfaceControl.screenshot can mutate it
|
||||||
Rect screenRect = new Rect(crop);
|
Rect screenRect = new Rect(crop);
|
||||||
Bitmap screenshot = captureScreenshot(crop);
|
Bitmap screenshot = captureScreenshot(crop);
|
||||||
@@ -661,7 +666,8 @@ public class ScreenshotController {
|
|||||||
Bitmap newScreenshot = captureScreenshot(
|
Bitmap newScreenshot = captureScreenshot(
|
||||||
new Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels));
|
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
|
// delay starting scroll capture to make sure the scrim is up before the app moves
|
||||||
mScreenshotView.post(() -> {
|
mScreenshotView.post(() -> {
|
||||||
// Clear the reference to prevent close() in dismissScreenshot
|
// Clear the reference to prevent close() in dismissScreenshot
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ public class ScreenshotView extends FrameLayout implements
|
|||||||
private GestureDetector mSwipeDetector;
|
private GestureDetector mSwipeDetector;
|
||||||
private SwipeDismissHandler mSwipeDismissHandler;
|
private SwipeDismissHandler mSwipeDismissHandler;
|
||||||
private InputMonitorCompat mInputMonitor;
|
private InputMonitorCompat mInputMonitor;
|
||||||
|
private boolean mShowScrollablePreview;
|
||||||
|
|
||||||
private final ArrayList<ScreenshotActionChip> mSmartChips = new ArrayList<>();
|
private final ArrayList<ScreenshotActionChip> mSmartChips = new ArrayList<>();
|
||||||
private PendingInteraction mPendingInteraction;
|
private PendingInteraction mPendingInteraction;
|
||||||
@@ -772,70 +773,99 @@ public class ScreenshotView extends FrameLayout implements
|
|||||||
|
|
||||||
void startLongScreenshotTransition(Rect destination, Runnable onTransitionEnd,
|
void startLongScreenshotTransition(Rect destination, Runnable onTransitionEnd,
|
||||||
ScrollCaptureController.LongScreenshot longScreenshot) {
|
ScrollCaptureController.LongScreenshot longScreenshot) {
|
||||||
mScrollablePreview.setImageBitmap(longScreenshot.toBitmap());
|
AnimatorSet animSet = new AnimatorSet();
|
||||||
ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
|
|
||||||
float startX = mScrollablePreview.getX();
|
ValueAnimator scrimAnim = ValueAnimator.ofFloat(0, 1);
|
||||||
float startY = mScrollablePreview.getY();
|
scrimAnim.addUpdateListener(animation ->
|
||||||
int[] locInScreen = mScrollablePreview.getLocationOnScreen();
|
mScrollingScrim.setAlpha(1 - animation.getAnimatedFraction()));
|
||||||
destination.offset((int) startX - locInScreen[0], (int) startY - locInScreen[1]);
|
|
||||||
mScrollablePreview.setPivotX(0);
|
if (mShowScrollablePreview) {
|
||||||
mScrollablePreview.setPivotY(0);
|
mScrollablePreview.setImageBitmap(longScreenshot.toBitmap());
|
||||||
mScrollablePreview.setAlpha(1f);
|
float startX = mScrollablePreview.getX();
|
||||||
float currentScale = mScrollablePreview.getWidth() / (float) longScreenshot.getWidth();
|
float startY = mScrollablePreview.getY();
|
||||||
Matrix matrix = new Matrix();
|
int[] locInScreen = mScrollablePreview.getLocationOnScreen();
|
||||||
matrix.setScale(currentScale, currentScale);
|
destination.offset((int) startX - locInScreen[0], (int) startY - locInScreen[1]);
|
||||||
matrix.postTranslate(
|
mScrollablePreview.setPivotX(0);
|
||||||
longScreenshot.getLeft() * currentScale, longScreenshot.getTop() * currentScale);
|
mScrollablePreview.setPivotY(0);
|
||||||
mScrollablePreview.setImageMatrix(matrix);
|
mScrollablePreview.setAlpha(1f);
|
||||||
float destinationScale = destination.width() / (float) mScrollablePreview.getWidth();
|
float currentScale = mScrollablePreview.getWidth() / (float) longScreenshot.getWidth();
|
||||||
anim.addUpdateListener(animation -> {
|
Matrix matrix = new Matrix();
|
||||||
float t = animation.getAnimatedFraction();
|
matrix.setScale(currentScale, currentScale);
|
||||||
mScrollingScrim.setAlpha(1 - t);
|
matrix.postTranslate(
|
||||||
float currScale = MathUtils.lerp(1, destinationScale, t);
|
longScreenshot.getLeft() * currentScale,
|
||||||
mScrollablePreview.setScaleX(currScale);
|
longScreenshot.getTop() * currentScale);
|
||||||
mScrollablePreview.setScaleY(currScale);
|
mScrollablePreview.setImageMatrix(matrix);
|
||||||
mScrollablePreview.setX(MathUtils.lerp(startX, destination.left, t));
|
float destinationScale = destination.width() / (float) mScrollablePreview.getWidth();
|
||||||
mScrollablePreview.setY(MathUtils.lerp(startY, destination.top, t));
|
|
||||||
});
|
ValueAnimator previewAnim = ValueAnimator.ofFloat(0, 1);
|
||||||
anim.addListener(new AnimatorListenerAdapter() {
|
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
|
@Override
|
||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
super.onAnimationEnd(animation);
|
super.onAnimationEnd(animation);
|
||||||
onTransitionEnd.run();
|
|
||||||
mScrollablePreview.animate().alpha(0).setListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
super.onAnimationEnd(animation);
|
|
||||||
mCallbacks.onDismiss();
|
mCallbacks.onDismiss();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
anim.start();
|
animSet.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareScrollingTransition(ScrollCaptureResponse response, Bitmap screenBitmap,
|
void prepareScrollingTransition(ScrollCaptureResponse response, Bitmap screenBitmap,
|
||||||
Bitmap newBitmap) {
|
Bitmap newBitmap, boolean screenshotTakenInPortrait) {
|
||||||
|
mShowScrollablePreview = (screenshotTakenInPortrait == mOrientationPortrait);
|
||||||
|
|
||||||
mScrollingScrim.setImageBitmap(newBitmap);
|
mScrollingScrim.setImageBitmap(newBitmap);
|
||||||
mScrollingScrim.setVisibility(View.VISIBLE);
|
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());
|
if (mShowScrollablePreview) {
|
||||||
params.height = (int) (scale * scrollableArea.height());
|
Rect scrollableArea = scrollableAreaOnScreen(response);
|
||||||
Matrix matrix = new Matrix();
|
|
||||||
matrix.setScale(scale, scale);
|
|
||||||
matrix.postTranslate(-scrollableArea.left * scale, -scrollableArea.top * scale);
|
|
||||||
|
|
||||||
mScrollablePreview.setTranslationX(scale * scrollableArea.left);
|
float scale = mCornerSizeX
|
||||||
mScrollablePreview.setTranslationY(scale * scrollableArea.top);
|
/ (mOrientationPortrait ? screenBitmap.getWidth() : screenBitmap.getHeight());
|
||||||
mScrollablePreview.setImageMatrix(matrix);
|
ConstraintLayout.LayoutParams params =
|
||||||
|
(ConstraintLayout.LayoutParams) mScrollablePreview.getLayoutParams();
|
||||||
|
|
||||||
mScrollablePreview.setImageBitmap(screenBitmap);
|
params.width = (int) (scale * scrollableArea.width());
|
||||||
mScrollablePreview.setVisibility(View.VISIBLE);
|
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);
|
mDismissButton.setVisibility(View.GONE);
|
||||||
mActionsContainer.setVisibility(View.GONE);
|
mActionsContainer.setVisibility(View.GONE);
|
||||||
mBackgroundProtection.setVisibility(View.GONE);
|
mBackgroundProtection.setVisibility(View.GONE);
|
||||||
@@ -919,6 +949,8 @@ public class ScreenshotView extends FrameLayout implements
|
|||||||
mActionsContainer.setVisibility(View.GONE);
|
mActionsContainer.setVisibility(View.GONE);
|
||||||
mBackgroundProtection.setAlpha(0f);
|
mBackgroundProtection.setAlpha(0f);
|
||||||
mDismissButton.setVisibility(View.GONE);
|
mDismissButton.setVisibility(View.GONE);
|
||||||
|
mScrollingScrim.setVisibility(View.GONE);
|
||||||
|
mScrollablePreview.setVisibility(View.GONE);
|
||||||
mScreenshotStatic.setTranslationX(0);
|
mScreenshotStatic.setTranslationX(0);
|
||||||
mScreenshotPreview.setTranslationY(0);
|
mScreenshotPreview.setTranslationY(0);
|
||||||
mScreenshotPreview.setContentDescription(
|
mScreenshotPreview.setContentDescription(
|
||||||
|
|||||||
Reference in New Issue
Block a user