Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cc47e53 authored by Matt Casey's avatar Matt Casey
Browse files

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
parent 4062430f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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"
+4 −2
Original line number Diff line number Diff line
@@ -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);