Merge "Fix CropView sizing on full-width images" into sc-dev

This commit is contained in:
Matt Casey
2021-03-22 18:50:15 +00:00
committed by Android (Google) Code Review
2 changed files with 9 additions and 7 deletions

View File

@@ -48,10 +48,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/save"
@@ -64,8 +64,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

@@ -409,7 +409,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
@@ -417,7 +419,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);