Fix CropView sizing on full-width images

Full width images happen when the long screenshot isn't particularly
long, typically an error case.

- Ensure that ImageView and CropView take up the whole space defined by
constraints.
- Set padding on ImageView, factor that padding into the image size
computation for CropView.

Bug: 183278746
Test: Validate correct crop bounds display on a full height and a full
      width long screenshot.
Change-Id: I0f71ddc051f8cf6d295a348fe3cae3cbe00e4077
This commit is contained in:
Matt Casey
2021-03-20 17:11:14 -04:00
parent 4062430f8b
commit 5cc47e5383
2 changed files with 9 additions and 7 deletions

View File

@@ -72,10 +72,10 @@
<ImageView
android:id="@+id/preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="0px"
android:layout_height="0px"
android:layout_marginBottom="42dp"
android:layout_marginHorizontal="48dp"
android:paddingHorizontal="48dp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintTop_toBottomOf="@id/guideline"
@@ -88,8 +88,8 @@
<com.android.systemui.screenshot.CropView
android:id="@+id/crop_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="0px"
android:layout_height="0px"
android:layout_marginBottom="42dp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"

View File

@@ -415,7 +415,9 @@ public class LongScreenshotActivity extends Activity {
}
Rect bounds = drawable.getBounds();
float imageRatio = bounds.width() / (float) bounds.height();
float viewRatio = mPreview.getWidth() / (float) mPreview.getHeight();
int previewWidth = mPreview.getWidth() - mPreview.getPaddingLeft()
- mPreview.getPaddingRight();
float viewRatio = previewWidth / (float) mPreview.getHeight();
if (imageRatio > viewRatio) {
// Image is full width and height is constrained, compute extra padding to inform
@@ -423,7 +425,7 @@ public class LongScreenshotActivity extends Activity {
float imageHeight = mPreview.getHeight() * viewRatio / imageRatio;
int extraPadding = (int) (mPreview.getHeight() - imageHeight) / 2;
mCropView.setExtraPadding(extraPadding, extraPadding);
mCropView.setImageWidth(mPreview.getWidth());
mCropView.setImageWidth(previewWidth);
} else {
// Image is full height
mCropView.setExtraPadding(0, 0);