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

Commit 61857f3f authored by Tony Wickham's avatar Tony Wickham
Browse files

Prevent edge gradient for screenshots in correct orientation

- Due to rounding issues, the width could be a pixel too small, causing
  a gradient on the right edge
- On tall devices, the height ratio of the task thumbnail might be
  larger than the width ratio, causing the screenshot to be too short
  upon swiping up, and thus a gradient on the bottom edge

Bug: 73540853
Change-Id: I1330cec3d2ff8c98eb1b354f0e7f40c6ea49ad7c
parent f6a8f955
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -323,11 +323,31 @@ public abstract class RecentsView<T extends BaseActivity>
        padding.bottom = profile.availableHeightPx - padding.top - sTempStableInsets.top
                - Math.round(overviewHeight);
        padding.left = padding.right = (int) ((profile.availableWidthPx - overviewWidth) / 2);

        // If the height ratio is larger than the width ratio, the screenshot will get cropped
        // at the bottom when swiping up. In this case, increase the top/bottom padding to make it
        // the same aspect ratio.
        Rect pageRect = new Rect();
        getPageRect(profile, context, pageRect, padding);
        float widthRatio = (float) pageRect.width() / taskWidth;
        float heightRatio = (float) pageRect.height() / taskHeight;
        if (heightRatio > widthRatio) {
            float additionalVerticalPadding = pageRect.height() - widthRatio * taskHeight;
            additionalVerticalPadding = Math.round(additionalVerticalPadding);
            padding.top += additionalVerticalPadding / 2;
            padding.bottom += additionalVerticalPadding / 2;
        }

        return padding;
    }

    public static void getPageRect(DeviceProfile grid, Context context, Rect outRect) {
        Rect targetPadding = getPadding(grid, context);
        getPageRect(grid, context, outRect, targetPadding);
    }

    private static void getPageRect(DeviceProfile grid, Context context, Rect outRect,
            Rect targetPadding) {
        Rect insets = grid.getInsets();
        outRect.set(
                targetPadding.left + insets.left,
+2 −2
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public class TaskThumbnailView extends View {

            float bitmapHeight = Math.max(thumbnailHeight * thumbnailScale, 0);
            Shader shader = mBitmapShader;
            if (bitmapHeight < getMeasuredHeight()) {
            if (Math.round(bitmapHeight) < getMeasuredHeight()) {
                int color = mPaint.getColor();
                LinearGradient fade = new LinearGradient(
                        0, bitmapHeight - mFadeLength, 0, bitmapHeight,
@@ -184,7 +184,7 @@ public class TaskThumbnailView extends View {
            }

            float bitmapWidth = Math.max(thumbnailWidth * thumbnailScale, 0);
            if (bitmapWidth < getMeasuredWidth()) {
            if (Math.round(bitmapWidth) < getMeasuredWidth()) {
                int color = mPaint.getColor();
                LinearGradient fade = new LinearGradient(
                        bitmapWidth - mFadeLength, 0, bitmapWidth, 0,