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

Commit 5ab588a4 authored by shawnlin's avatar shawnlin
Browse files

Provides apps the rounded corners info

- Created a new @hide class RoundedCorners
  - The class is used to create and manager all the rounded corners.
- Created a new public class RoundedCorner
  - Represent each rounded corner.
- Created a new public API in Display to get the original rounded
  corners.
- Created a new public API in WindowInsets to get the rounded corners
  relative to the window bounds.

Bug: 161808676
Test: atest RoundedCornerTest RoundedCornersTest
      DisplayPolicyLayoutTests DisplayPolicyTests
      WallpaperControllerTests
Change-Id: I58c671b0e9a077cdf26764c6302537c72db0f667
parent d9b723b8
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -46120,6 +46120,7 @@ package android.view {
    method @Deprecated public void getRectSize(android.graphics.Rect);
    method public float getRefreshRate();
    method public int getRotation();
    method @Nullable public android.view.RoundedCorner getRoundedCorner(int);
    method @Deprecated public void getSize(android.graphics.Point);
    method public int getState();
    method public android.view.Display.Mode[] getSupportedModes();
@@ -47373,6 +47374,20 @@ package android.view {
    field public static final int TYPE_ZOOM_OUT = 1019; // 0x3fb
  }
  public final class RoundedCorner implements android.os.Parcelable {
    ctor public RoundedCorner(int, int, int, int);
    method public int describeContents();
    method @NonNull public android.graphics.Point getCenter();
    method public int getPosition();
    method public int getRadius();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.RoundedCorner> CREATOR;
    field public static final int POSITION_BOTTOM_LEFT = 3; // 0x3
    field public static final int POSITION_BOTTOM_RIGHT = 2; // 0x2
    field public static final int POSITION_TOP_LEFT = 0; // 0x0
    field public static final int POSITION_TOP_RIGHT = 1; // 0x1
  }
  public class ScaleGestureDetector {
    ctor public ScaleGestureDetector(android.content.Context, android.view.ScaleGestureDetector.OnScaleGestureListener);
    ctor public ScaleGestureDetector(android.content.Context, android.view.ScaleGestureDetector.OnScaleGestureListener, android.os.Handler);
@@ -49382,6 +49397,7 @@ package android.view {
    method @NonNull public android.graphics.Insets getInsets(int);
    method @NonNull public android.graphics.Insets getInsetsIgnoringVisibility(int);
    method @Deprecated @NonNull public android.graphics.Insets getMandatorySystemGestureInsets();
    method @Nullable public android.view.RoundedCorner getRoundedCorner(int);
    method @Deprecated public int getStableInsetBottom();
    method @Deprecated public int getStableInsetLeft();
    method @Deprecated public int getStableInsetRight();
@@ -49415,6 +49431,7 @@ package android.view {
    method @NonNull public android.view.WindowInsets.Builder setInsets(int, @NonNull android.graphics.Insets);
    method @NonNull public android.view.WindowInsets.Builder setInsetsIgnoringVisibility(int, @NonNull android.graphics.Insets) throws java.lang.IllegalArgumentException;
    method @Deprecated @NonNull public android.view.WindowInsets.Builder setMandatorySystemGestureInsets(@NonNull android.graphics.Insets);
    method @NonNull public android.view.WindowInsets.Builder setRoundedCorner(int, @Nullable android.view.RoundedCorner);
    method @Deprecated @NonNull public android.view.WindowInsets.Builder setStableInsets(@NonNull android.graphics.Insets);
    method @Deprecated @NonNull public android.view.WindowInsets.Builder setSystemGestureInsets(@NonNull android.graphics.Insets);
    method @Deprecated @NonNull public android.view.WindowInsets.Builder setSystemWindowInsets(@NonNull android.graphics.Insets);
+26 −0
Original line number Diff line number Diff line
@@ -899,6 +899,32 @@ public final class Display {
        }
    }

    /**
     * Returns the {@link RoundedCorner} of the given position if there is one.
     *
     * @param position the position of the rounded corner on the display.
     *
     * @return the rounded corner of the given position. Returns {@code null} if there is none.
     */
    @SuppressLint("VisiblySynchronized")
    @Nullable
    public RoundedCorner getRoundedCorner(@RoundedCorner.Position int position) {
        synchronized (this) {
            updateDisplayInfoLocked();
            RoundedCorners roundedCorners;
            if (mMayAdjustByFixedRotation) {
                roundedCorners = getDisplayAdjustments().adjustRoundedCorner(
                        mDisplayInfo.roundedCorners,
                        mDisplayInfo.rotation,
                        mDisplayInfo.logicalWidth,
                        mDisplayInfo.logicalHeight);
            } else {
                roundedCorners = mDisplayInfo.roundedCorners;
            }
            return roundedCorners == null ? null : roundedCorners.getRoundedCorner(position);
        }
    }

    /**
     * Gets the pixel format of the display.
     * @return One of the constants defined in {@link android.graphics.PixelFormat}.
+17 −0
Original line number Diff line number Diff line
@@ -151,6 +151,23 @@ public class DisplayAdjustments {
                : realCutout;
    }

    /**
     * Returns the adjusted {@link RoundedCorners} if available. Otherwise the original
     * {@link RoundedCorners} is returned.
     */
    @Nullable
    public RoundedCorners adjustRoundedCorner(@Nullable RoundedCorners realRoundedCorners,
            @Surface.Rotation int realRotation, int displayWidth, int displayHeight) {
        final FixedRotationAdjustments rotationAdjustments = mFixedRotationAdjustments;
        if (realRoundedCorners == null || rotationAdjustments == null
                || rotationAdjustments.mRotation == realRotation) {
            return realRoundedCorners;
        }

        return realRoundedCorners.rotate(
                rotationAdjustments.mRotation, displayWidth, displayHeight);
    }

    /** Returns the adjusted rotation if available. Otherwise the original rotation is returned. */
    @Surface.Rotation
    public int getRotation(@Surface.Rotation int realRotation) {
+11 −1
Original line number Diff line number Diff line
@@ -301,6 +301,12 @@ public final class DisplayInfo implements Parcelable {
     */
    public float brightnessDefault;

    /**
     * The {@link RoundedCorners} if present, otherwise {@code null}.
     */
    @Nullable
    public RoundedCorners roundedCorners;

    public static final @android.annotation.NonNull Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
        @Override
        public DisplayInfo createFromParcel(Parcel source) {
@@ -369,7 +375,8 @@ public final class DisplayInfo implements Parcelable {
                && refreshRateOverride == other.refreshRateOverride
                && brightnessMinimum == other.brightnessMinimum
                && brightnessMaximum == other.brightnessMaximum
                && brightnessDefault == other.brightnessDefault;
                && brightnessDefault == other.brightnessDefault
                && Objects.equals(roundedCorners, other.roundedCorners);
    }

    @Override
@@ -418,6 +425,7 @@ public final class DisplayInfo implements Parcelable {
        brightnessMinimum = other.brightnessMinimum;
        brightnessMaximum = other.brightnessMaximum;
        brightnessDefault = other.brightnessDefault;
        roundedCorners = other.roundedCorners;
    }

    public void readFromParcel(Parcel source) {
@@ -468,6 +476,7 @@ public final class DisplayInfo implements Parcelable {
        brightnessMinimum = source.readFloat();
        brightnessMaximum = source.readFloat();
        brightnessDefault = source.readFloat();
        roundedCorners = source.readTypedObject(RoundedCorners.CREATOR);
    }

    @Override
@@ -517,6 +526,7 @@ public final class DisplayInfo implements Parcelable {
        dest.writeFloat(brightnessMinimum);
        dest.writeFloat(brightnessMaximum);
        dest.writeFloat(brightnessDefault);
        dest.writeTypedObject(roundedCorners, flags);
    }

    @Override
+1 −0
Original line number Diff line number Diff line
@@ -653,6 +653,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private void updateState(InsetsState newState) {
        mState.setDisplayFrame(newState.getDisplayFrame());
        mState.setDisplayCutout(newState.getDisplayCutout());
        mState.setRoundedCorners(newState.getRoundedCorners());
        @InsetsType int disabledUserAnimationTypes = 0;
        @InsetsType int[] cancelledUserAnimationTypes = {0};
        for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) {
Loading