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

Commit 1e69ad01 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add PictureInPictureParams#isSameAspectRatio [1/N]" into main

parents 9b48407b 8232c305
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -423,6 +423,7 @@ package android.app {
  public final class PictureInPictureParams implements android.os.Parcelable {
    method public float getAspectRatioFloat();
    method public float getExpandedAspectRatioFloat();
    method public static boolean isSameAspectRatio(@NonNull android.graphics.Rect, @NonNull android.util.Rational);
  }

  public final class PictureInPictureUiState implements android.os.Parcelable {
+27 −0
Original line number Diff line number Diff line
@@ -654,6 +654,33 @@ public final class PictureInPictureParams implements Parcelable {
                && !hasSetSubtitle() && mIsLaunchIntoPip == null;
    }

    /**
     * Compare a given {@link Rect} against the aspect ratio, with rounding error tolerance.
     * @param bounds The {@link Rect} represents the source rect hint, this check is not needed
     *               if app provides a null source rect hint.
     * @param aspectRatio {@link Rational} representation of aspect ratio, this check is not needed
     *                    if app provides a null aspect ratio.
     * @return {@code true} if the given {@link Rect} matches the aspect ratio.
     * @hide
     */
    @SuppressWarnings("UnflaggedApi")
    @TestApi
    public static boolean isSameAspectRatio(@NonNull Rect bounds, @NonNull Rational aspectRatio) {
        // Validations
        if (bounds.isEmpty() || aspectRatio.floatValue() <= 0) {
            return false;
        }
        // Check against both the width and height.
        final int exactWidth = (aspectRatio.getNumerator() * bounds.height())
                / aspectRatio.getDenominator();
        if (Math.abs(exactWidth - bounds.width()) <= 1) {
            return true;
        }
        final int exactHeight = (aspectRatio.getDenominator() * bounds.width())
                / aspectRatio.getNumerator();
        return Math.abs(exactHeight - bounds.height()) <= 1;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;