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

Commit db861395 authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge "Make pip size spec calculations more precise" into udc-dev

parents cebcf126 b5fd7154
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -135,14 +135,14 @@ public class PipSizeSpecHandler {
                maxWidth = (int) (mOptimizedAspectRatio * shorterLength
                        + shorterLength * (aspectRatio - mOptimizedAspectRatio) / (1
                        + aspectRatio));
                maxHeight = (int) (maxWidth / aspectRatio);
                maxHeight = Math.round(maxWidth / aspectRatio);
            } else {
                if (aspectRatio > 1f) {
                    maxWidth = shorterLength;
                    maxHeight = (int) (maxWidth / aspectRatio);
                    maxHeight = Math.round(maxWidth / aspectRatio);
                } else {
                    maxHeight = shorterLength;
                    maxWidth = (int) (maxHeight * aspectRatio);
                    maxWidth = Math.round(maxHeight * aspectRatio);
                }
            }

@@ -165,10 +165,9 @@ public class PipSizeSpecHandler {

            Size maxSize = this.getMaxSize(aspectRatio);

            int defaultWidth = Math.max((int) (maxSize.getWidth() * mDefaultSizePercent),
            int defaultWidth = Math.max(Math.round(maxSize.getWidth() * mDefaultSizePercent),
                    minSize.getWidth());
            int defaultHeight = Math.max((int) (maxSize.getHeight() * mDefaultSizePercent),
                    minSize.getHeight());
            int defaultHeight = Math.round(defaultWidth / aspectRatio);

            return new Size(defaultWidth, defaultHeight);
        }
@@ -188,16 +187,16 @@ public class PipSizeSpecHandler {

            Size maxSize = this.getMaxSize(aspectRatio);

            int minWidth = (int) (maxSize.getWidth() * mMinimumSizePercent);
            int minHeight = (int) (maxSize.getHeight() * mMinimumSizePercent);
            int minWidth = Math.round(maxSize.getWidth() * mMinimumSizePercent);
            int minHeight = Math.round(maxSize.getHeight() * mMinimumSizePercent);

            // make sure the calculated min size is not smaller than the allowed default min size
            if (aspectRatio > 1f) {
                minHeight = (int) Math.max(minHeight, mDefaultMinSize);
                minWidth = (int) (minHeight * aspectRatio);
                minHeight = Math.max(minHeight, mDefaultMinSize);
                minWidth = Math.round(minHeight * aspectRatio);
            } else {
                minWidth = (int) Math.max(minWidth, mDefaultMinSize);
                minHeight = (int) (minWidth / aspectRatio);
                minWidth = Math.max(minWidth, mDefaultMinSize);
                minHeight = Math.round(minWidth / aspectRatio);
            }
            return new Size(minWidth, minHeight);
        }
+6 −6
Original line number Diff line number Diff line
@@ -106,21 +106,21 @@ public class PipSizeSpecHandlerTest extends ShellTestCase {
        sExpectedDefaultSizes = new HashMap<>();
        sExpectedMinSizes = new HashMap<>();

        sExpectedMaxSizes.put(16f / 9, new Size(1000, 562));
        sExpectedDefaultSizes.put(16f / 9, new Size(600, 337));
        sExpectedMinSizes.put(16f / 9, new Size(499, 281));
        sExpectedMaxSizes.put(16f / 9, new Size(1000, 563));
        sExpectedDefaultSizes.put(16f / 9, new Size(600, 338));
        sExpectedMinSizes.put(16f / 9, new Size(501, 282));

        sExpectedMaxSizes.put(4f / 3, new Size(892, 669));
        sExpectedDefaultSizes.put(4f / 3, new Size(535, 401));
        sExpectedMinSizes.put(4f / 3, new Size(445, 334));
        sExpectedMinSizes.put(4f / 3, new Size(447, 335));

        sExpectedMaxSizes.put(3f / 4, new Size(669, 892));
        sExpectedDefaultSizes.put(3f / 4, new Size(401, 535));
        sExpectedMinSizes.put(3f / 4, new Size(334, 445));
        sExpectedMinSizes.put(3f / 4, new Size(335, 447));

        sExpectedMaxSizes.put(9f / 16, new Size(562, 999));
        sExpectedDefaultSizes.put(9f / 16, new Size(337, 599));
        sExpectedMinSizes.put(9f / 16, new Size(281, 499));
        sExpectedMinSizes.put(9f / 16, new Size(281, 500));
    }

    private void forEveryTestCaseCheck(Map<Float, Size> expectedSizes,