Move screenshot UI to avoid covering nav bar

Bug: 193552343
Fix: 193552343
Test: manual; visual inspection
Change-Id: Idbf632c268cb753079d432cbe197f06e9abaf11d
This commit is contained in:
Miranda Kephart
2021-07-15 11:49:23 -04:00
parent e421c1c291
commit 9eb0f18a8d
4 changed files with 22 additions and 16 deletions

View File

@@ -36,7 +36,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/screenshot_action_container_margin_horizontal"
android:layout_marginBottom="@dimen/screenshot_action_container_offset_y"
android:paddingEnd="@dimen/screenshot_action_container_padding_right"
android:paddingVertical="@dimen/screenshot_action_container_padding_vertical"
android:elevation="1dp"

View File

@@ -331,11 +331,10 @@
<dimen name="global_screenshot_x_scale">80dp</dimen>
<dimen name="screenshot_bg_protection_height">242dp</dimen>
<dimen name="screenshot_preview_elevation">4dp</dimen>
<dimen name="screenshot_offset_y">24dp</dimen>
<dimen name="screenshot_offset_y">8dp</dimen>
<dimen name="screenshot_offset_x">16dp</dimen>
<dimen name="screenshot_dismiss_button_tappable_size">48dp</dimen>
<dimen name="screenshot_dismiss_button_margin">8dp</dimen>
<dimen name="screenshot_action_container_offset_y">16dp</dimen>
<dimen name="screenshot_action_container_corner_radius">18dp</dimen>
<dimen name="screenshot_action_container_padding_vertical">4dp</dimen>
<dimen name="screenshot_action_container_margin_horizontal">8dp</dimen>

View File

@@ -559,8 +559,8 @@ public class ScreenshotController {
mScreenshotView.reset();
}
mScreenshotView.updateOrientation(mWindowManager.getCurrentWindowMetrics()
.getWindowInsets().getDisplayCutout());
mScreenshotView.updateOrientation(
mWindowManager.getCurrentWindowMetrics().getWindowInsets());
mScreenBitmap = screenshot;
@@ -594,9 +594,8 @@ public class ScreenshotController {
// Delay scroll capture eval a bit to allow the underlying activity
// to set up in the new orientation.
mScreenshotHandler.postDelayed(this::requestScrollCapture, 150);
mScreenshotView.updateDisplayCutoutMargins(
mWindowManager.getCurrentWindowMetrics().getWindowInsets()
.getDisplayCutout());
mScreenshotView.updateInsets(
mWindowManager.getCurrentWindowMetrics().getWindowInsets());
// screenshot animation calculations won't be valid anymore, so just end
if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) {
mScreenshotAnimation.end();

View File

@@ -414,21 +414,30 @@ public class ScreenshotView extends FrameLayout implements
mScreenshotPreview.setImageDrawable(createScreenDrawable(mResources, bitmap, screenInsets));
}
void updateDisplayCutoutMargins(DisplayCutout cutout) {
void updateInsets(WindowInsets insets) {
int orientation = mContext.getResources().getConfiguration().orientation;
mOrientationPortrait = (orientation == ORIENTATION_PORTRAIT);
FrameLayout.LayoutParams p =
(FrameLayout.LayoutParams) mScreenshotStatic.getLayoutParams();
DisplayCutout cutout = insets.getDisplayCutout();
Insets navBarInsets = insets.getInsets(WindowInsets.Type.navigationBars());
if (cutout == null) {
p.setMargins(0, 0, 0, 0);
p.setMargins(0, 0, 0, navBarInsets.bottom);
} else {
Insets waterfall = cutout.getWaterfallInsets();
if (mOrientationPortrait) {
p.setMargins(waterfall.left, Math.max(cutout.getSafeInsetTop(), waterfall.top),
waterfall.right, Math.max(cutout.getSafeInsetBottom(), waterfall.bottom));
p.setMargins(
waterfall.left,
Math.max(cutout.getSafeInsetTop(), waterfall.top),
waterfall.right,
Math.max(cutout.getSafeInsetBottom(),
Math.max(navBarInsets.bottom, waterfall.bottom)));
} else {
p.setMargins(Math.max(cutout.getSafeInsetLeft(), waterfall.left), waterfall.top,
Math.max(cutout.getSafeInsetRight(), waterfall.right), waterfall.bottom);
p.setMargins(
Math.max(cutout.getSafeInsetLeft(), waterfall.left),
waterfall.top,
Math.max(cutout.getSafeInsetRight(), waterfall.right),
Math.max(navBarInsets.bottom, waterfall.bottom));
}
}
mStaticLeftMargin = p.leftMargin;
@@ -436,10 +445,10 @@ public class ScreenshotView extends FrameLayout implements
mScreenshotStatic.requestLayout();
}
void updateOrientation(DisplayCutout cutout) {
void updateOrientation(WindowInsets insets) {
int orientation = mContext.getResources().getConfiguration().orientation;
mOrientationPortrait = (orientation == ORIENTATION_PORTRAIT);
updateDisplayCutoutMargins(cutout);
updateInsets(insets);
int screenshotFixedSize =
mContext.getResources().getDimensionPixelSize(R.dimen.global_screenshot_x_scale);
ViewGroup.LayoutParams params = mScreenshotPreview.getLayoutParams();