From da72d6dae4633d476e7333480b3cb7ed764c7951 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Tue, 8 Jun 2021 10:47:05 -0400 Subject: [PATCH] Request scroll capture when the screen rotates. Show/hide the scroll capture button based upon availability of scrollable content in the underlying app. Needed a little delay after rotation to allow the underlying app to adjust to the new orientation (otherwise it was always not scrollable). Bug: 185897865 Test: Take screenshot, observe capture more, rotate, tap capture more. Test: Take screenshot of an activity that scrolls in portrait but not landcape, rotate the phone and observe the capture more button appearing and disappearing appropriately. Change-Id: I0015adee77e576549509468486936c57ec62a2fd --- .../screenshot/ScreenshotController.java | 23 +++++++++++++------ .../systemui/screenshot/ScreenshotView.java | 4 ++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 1f9221c2956f4..eaa6659790fa6 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -554,16 +554,15 @@ public class ScreenshotController { // Wait until this window is attached to request because it is // the reference used to locate the target window (below). withWindowAttached(() -> { - mScrollCaptureClient.setHostWindowToken(mWindow.getDecorView().getWindowToken()); - if (mLastScrollCaptureRequest != null) { - mLastScrollCaptureRequest.cancel(true); - } - mLastScrollCaptureRequest = mScrollCaptureClient.request(DEFAULT_DISPLAY); - mLastScrollCaptureRequest.addListener(() -> - onScrollCaptureResponseReady(mLastScrollCaptureRequest), mMainExecutor); + requestScrollCapture(); mWindow.peekDecorView().getViewRootImpl().setActivityConfigCallback( (overrideConfig, newDisplayId) -> { if (mConfigChanges.applyNewConfig(mContext.getResources())) { + // Hide the scroll chip until we know it's available in this orientation + mScreenshotView.hideScrollChip(); + // Delay scroll capture eval a bit to allow the underlying activity + // to set up in the new orientation. + mScreenshotHandler.postDelayed(this::requestScrollCapture, 150); updateDisplayCutout(); } }); @@ -593,6 +592,16 @@ public class ScreenshotController { cancelTimeout(); // restarted after animation } + private void requestScrollCapture() { + mScrollCaptureClient.setHostWindowToken(mWindow.getDecorView().getWindowToken()); + if (mLastScrollCaptureRequest != null) { + mLastScrollCaptureRequest.cancel(true); + } + mLastScrollCaptureRequest = mScrollCaptureClient.request(DEFAULT_DISPLAY); + mLastScrollCaptureRequest.addListener(() -> + onScrollCaptureResponseReady(mLastScrollCaptureRequest), mMainExecutor); + } + private void onScrollCaptureResponseReady(Future responseFuture) { try { if (mLastScrollCaptureResponse != null) { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java index facebee52943f..77e1d154f3ac6 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java @@ -204,6 +204,10 @@ public class ScreenshotView extends FrameLayout implements mSwipeDismissHandler = new SwipeDismissHandler(); } + public void hideScrollChip() { + mScrollChip.setVisibility(View.GONE); + } + /** * Called to display the scroll action chip when support is detected. *