From 1f757a98d8b3865dfb563a234e755662933dd4e5 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Thu, 1 Apr 2021 11:31:46 -0400 Subject: [PATCH] Add extra padding to long screenshot crop Modify padding code to account for this handling properly. Test: Test on full width and full height images, ensure touch area expanded into padding, handles visible at edges. Bug: 183278748 Change-Id: I083527467940206286ec485f92e56f0c19327219 --- packages/SystemUI/res/layout/long_screenshot.xml | 6 ++++-- .../screenshot/LongScreenshotActivity.java | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/res/layout/long_screenshot.xml b/packages/SystemUI/res/layout/long_screenshot.xml index 6d44138c53546..99af321305b1f 100644 --- a/packages/SystemUI/res/layout/long_screenshot.xml +++ b/packages/SystemUI/res/layout/long_screenshot.xml @@ -50,8 +50,9 @@ android:id="@+id/preview" android:layout_width="0px" android:layout_height="0px" - android:layout_marginBottom="42dp" android:paddingHorizontal="48dp" + android:paddingTop="8dp" + android:paddingBottom="42dp" app:layout_constrainedHeight="true" app:layout_constrainedWidth="true" app:layout_constraintTop_toBottomOf="@id/save" @@ -66,7 +67,8 @@ android:id="@+id/crop_view" android:layout_width="0px" android:layout_height="0px" - android:layout_marginBottom="42dp" + android:paddingTop="8dp" + android:paddingBottom="42dp" app:layout_constrainedHeight="true" app:layout_constrainedWidth="true" app:layout_constraintTop_toTopOf="@id/preview" diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java b/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java index 04d199645b24b..9ce0eebfd4411 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java @@ -411,19 +411,22 @@ public class LongScreenshotActivity extends Activity { float imageRatio = bounds.width() / (float) bounds.height(); int previewWidth = mPreview.getWidth() - mPreview.getPaddingLeft() - mPreview.getPaddingRight(); - float viewRatio = previewWidth / (float) mPreview.getHeight(); + int previewHeight = mPreview.getHeight() - mPreview.getPaddingTop() + - mPreview.getPaddingBottom(); + float viewRatio = previewWidth / (float) previewHeight; if (imageRatio > viewRatio) { // Image is full width and height is constrained, compute extra padding to inform // CropView - float imageHeight = mPreview.getHeight() * viewRatio / imageRatio; - int extraPadding = (int) (mPreview.getHeight() - imageHeight) / 2; - mCropView.setExtraPadding(extraPadding, extraPadding); + float imageHeight = previewHeight * viewRatio / imageRatio; + int extraPadding = (int) (previewHeight - imageHeight) / 2; + mCropView.setExtraPadding(extraPadding + mPreview.getPaddingTop(), + extraPadding + mPreview.getPaddingBottom()); mCropView.setImageWidth(previewWidth); } else { // Image is full height - mCropView.setExtraPadding(0, 0); - mCropView.setImageWidth((int) (mPreview.getHeight() * imageRatio)); + mCropView.setExtraPadding(mPreview.getPaddingTop(), mPreview.getPaddingBottom()); + mCropView.setImageWidth((int) (previewHeight * imageRatio)); } }