Fix repeated screenshots in landscape
Currently, if a screenshot is taken, then the phone is rotated while the UI is still up, the UI will correctly rotate but successive screenshots will fail. This change alters the way we handle rotations so that we update dynamically rarther than needing to reload the UI. Bug: 187238867 Fix: 187238867 Test: manual Change-Id: I3ebfd6a06fb5d4653ba4d267dcfb11c381eda105
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2020 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/global_screenshot_preview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/global_screenshot_x_scale"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="@dimen/screenshot_offset_x"
|
||||
android:layout_marginBottom="@dimen/screenshot_offset_y"
|
||||
android:scaleType="fitStart"
|
||||
android:elevation="@dimen/screenshot_preview_elevation"
|
||||
android:visibility="invisible"
|
||||
android:background="@drawable/screenshot_rounded_corners"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/screenshot_edit_label"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
@@ -401,9 +401,6 @@ public class ScreenshotController {
|
||||
if (DEBUG_UI) {
|
||||
Log.d(TAG, "reloadAssets()");
|
||||
}
|
||||
if (mScreenshotView != null && mScreenshotView.isAttachedToWindow()) {
|
||||
mWindow.clearContentView(); // Is there a simpler way to say "remove screenshotView?"
|
||||
}
|
||||
|
||||
// respect the display cutout in landscape (since we'd otherwise overlap) but not portrait
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
@@ -497,6 +494,17 @@ public class ScreenshotController {
|
||||
saveScreenshot(screenshot, finisher, screenRect, Insets.NONE, true);
|
||||
}
|
||||
|
||||
private void updateDisplayCutout() {
|
||||
// respect the display cutout in landscape (since we'd otherwise overlap) but not portrait
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
mWindowLayoutParams.setFitInsetsTypes(
|
||||
orientation == ORIENTATION_PORTRAIT ? 0 : WindowInsets.Type.displayCutout());
|
||||
final View decorView = mWindow.peekDecorView();
|
||||
if (decorView != null && decorView.isAttachedToWindow()) {
|
||||
mWindowManager.updateViewLayout(decorView, mWindowLayoutParams);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect screenRect,
|
||||
Insets screenInsets, boolean showFlash) {
|
||||
if (mAccessibilityManager.isEnabled()) {
|
||||
@@ -507,12 +515,6 @@ public class ScreenshotController {
|
||||
mAccessibilityManager.sendAccessibilityEvent(event);
|
||||
}
|
||||
|
||||
if (mConfigChanges.applyNewConfig(mContext.getResources())) {
|
||||
if (DEBUG_UI) {
|
||||
Log.d(TAG, "saveScreenshot: reloading assets");
|
||||
}
|
||||
reloadAssets();
|
||||
}
|
||||
|
||||
if (mScreenshotView.isAttachedToWindow()) {
|
||||
// if we didn't already dismiss for another reason
|
||||
@@ -526,6 +528,9 @@ public class ScreenshotController {
|
||||
mScreenshotView.reset();
|
||||
}
|
||||
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
mScreenshotView.updateOrientation(orientation == ORIENTATION_PORTRAIT);
|
||||
|
||||
mScreenBitmap = screenshot;
|
||||
|
||||
if (!isUserSetupComplete()) {
|
||||
@@ -556,6 +561,12 @@ public class ScreenshotController {
|
||||
mLastScrollCaptureRequest = mScrollCaptureClient.request(DEFAULT_DISPLAY);
|
||||
mLastScrollCaptureRequest.addListener(() ->
|
||||
onScrollCaptureResponseReady(mLastScrollCaptureRequest), mMainExecutor);
|
||||
mWindow.peekDecorView().getViewRootImpl().setActivityConfigCallback(
|
||||
(overrideConfig, newDisplayId) -> {
|
||||
if (mConfigChanges.applyNewConfig(mContext.getResources())) {
|
||||
updateDisplayCutout();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
attachWindow();
|
||||
|
||||
@@ -60,6 +60,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.TouchDelegate;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewOutlineProvider;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowInsets;
|
||||
@@ -350,6 +351,23 @@ public class ScreenshotView extends FrameLayout implements
|
||||
mScreenshotPreview.setImageDrawable(createScreenDrawable(mResources, bitmap, screenInsets));
|
||||
}
|
||||
|
||||
void updateOrientation(boolean portrait) {
|
||||
mOrientationPortrait = portrait;
|
||||
int screenshotFixedSize =
|
||||
mContext.getResources().getDimensionPixelSize(R.dimen.global_screenshot_x_scale);
|
||||
ViewGroup.LayoutParams params = mScreenshotPreview.getLayoutParams();
|
||||
if (portrait) {
|
||||
params.width = screenshotFixedSize;
|
||||
params.height = LayoutParams.WRAP_CONTENT;
|
||||
mScreenshotPreview.setScaleType(ImageView.ScaleType.FIT_START);
|
||||
} else {
|
||||
params.width = LayoutParams.WRAP_CONTENT;
|
||||
params.height = screenshotFixedSize;
|
||||
mScreenshotPreview.setScaleType(ImageView.ScaleType.FIT_END);
|
||||
}
|
||||
mScreenshotPreview.setLayoutParams(params);
|
||||
}
|
||||
|
||||
AnimatorSet createScreenshotDropInAnimation(Rect bounds, boolean showFlash) {
|
||||
if (DEBUG_ANIM) {
|
||||
Log.d(TAG, "createAnim: bounds=" + bounds + " showFlash=" + showFlash);
|
||||
|
||||
Reference in New Issue
Block a user