summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Shawn Lin <shawnlin@google.com> 2022-01-18 13:23:15 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-01-18 13:23:15 +0000
commit08dc50bbbc3f66151f455b847edfc7c7baf6eeaf (patch)
tree2a7d0161932a490c283e6e1713b4d1be6a8ef92f
parent1a58f4a793f0d3b9851e9f2f9ec52c3de0860543 (diff)
parent113c28722b0f461a195f1f425349241eba3528c9 (diff)
Merge "Add an public api to create a DisplayCutout with path for test only"
-rw-r--r--core/api/current.txt12
-rw-r--r--core/java/android/view/DisplayCutout.java115
2 files changed, 127 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index d04e5c030dd7..3cd177afae6e 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -48193,6 +48193,18 @@ package android.view {
method @NonNull public android.graphics.Insets getWaterfallInsets();
}
+ public static final class DisplayCutout.Builder {
+ ctor public DisplayCutout.Builder();
+ method @NonNull public android.view.DisplayCutout build();
+ method @NonNull public android.view.DisplayCutout.Builder setBoundingRectBottom(@NonNull android.graphics.Rect);
+ method @NonNull public android.view.DisplayCutout.Builder setBoundingRectLeft(@NonNull android.graphics.Rect);
+ method @NonNull public android.view.DisplayCutout.Builder setBoundingRectRight(@NonNull android.graphics.Rect);
+ method @NonNull public android.view.DisplayCutout.Builder setBoundingRectTop(@NonNull android.graphics.Rect);
+ method @NonNull public android.view.DisplayCutout.Builder setCutoutPath(@NonNull android.graphics.Path);
+ method @NonNull public android.view.DisplayCutout.Builder setSafeInsets(@NonNull android.graphics.Insets);
+ method @NonNull public android.view.DisplayCutout.Builder setWaterfallInsets(@NonNull android.graphics.Insets);
+ }
+
public final class DragAndDropPermissions implements android.os.Parcelable {
method public int describeContents();
method public void release();
diff --git a/core/java/android/view/DisplayCutout.java b/core/java/android/view/DisplayCutout.java
index ae323226d9cc..9889eaaf12e3 100644
--- a/core/java/android/view/DisplayCutout.java
+++ b/core/java/android/view/DisplayCutout.java
@@ -1249,4 +1249,119 @@ public final class DisplayCutout {
return String.valueOf(mInner);
}
}
+
+ /**
+ * A Builder class to construct a DisplayCutout instance.
+ *
+ * <p>Note that this is only for tests purpose. For production code, developers should always
+ * use a {@link DisplayCutout} obtained from the system.</p>
+ */
+ public static final class Builder {
+ private Insets mSafeInsets = Insets.NONE;
+ private Insets mWaterfallInsets = Insets.NONE;
+ private Path mCutoutPath;
+ private final Rect mBoundingRectLeft = new Rect();
+ private final Rect mBoundingRectTop = new Rect();
+ private final Rect mBoundingRectRight = new Rect();
+ private final Rect mBoundingRectBottom = new Rect();
+
+ /**
+ * Begin building a DisplayCutout.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Construct a new {@link DisplayCutout} with the set parameters.
+ */
+ @NonNull
+ public DisplayCutout build() {
+ final CutoutPathParserInfo info;
+ if (mCutoutPath != null) {
+ // Create a fake CutoutPathParserInfo and set it to sCachedCutoutPathParserInfo so
+ // that when getCutoutPath() is called, it will return the cached Path.
+ info = new CutoutPathParserInfo(0, 0, 0, "test", 0, 1f);
+ synchronized (CACHE_LOCK) {
+ DisplayCutout.sCachedCutoutPathParserInfo = info;
+ DisplayCutout.sCachedCutoutPath = mCutoutPath;
+ }
+ } else {
+ info = null;
+ }
+ return new DisplayCutout(mSafeInsets.toRect(), mWaterfallInsets, mBoundingRectLeft,
+ mBoundingRectTop, mBoundingRectRight, mBoundingRectBottom, info, false);
+ }
+
+ /**
+ * Set the safe insets. If not set, the default value is {@link Insets#NONE}.
+ */
+ @SuppressWarnings("MissingGetterMatchingBuilder")
+ @NonNull
+ public Builder setSafeInsets(@NonNull Insets safeInsets) {
+ mSafeInsets = safeInsets;
+ return this;
+ }
+
+ /**
+ * Set the waterfall insets of the DisplayCutout. If not set, the default value is
+ * {@link Insets#NONE}
+ */
+ @NonNull
+ public Builder setWaterfallInsets(@NonNull Insets waterfallInsets) {
+ mWaterfallInsets = waterfallInsets;
+ return this;
+ }
+
+ /**
+ * Set a bounding rectangle for a non-functional area on the display which is located on
+ * the left of the screen. If not set, the default value is an empty rectangle.
+ */
+ @NonNull
+ public Builder setBoundingRectLeft(@NonNull Rect boundingRectLeft) {
+ mBoundingRectLeft.set(boundingRectLeft);
+ return this;
+ }
+
+ /**
+ * Set a bounding rectangle for a non-functional area on the display which is located on
+ * the top of the screen. If not set, the default value is an empty rectangle.
+ */
+ @NonNull
+ public Builder setBoundingRectTop(@NonNull Rect boundingRectTop) {
+ mBoundingRectTop.set(boundingRectTop);
+ return this;
+ }
+
+ /**
+ * Set a bounding rectangle for a non-functional area on the display which is located on
+ * the right of the screen. If not set, the default value is an empty rectangle.
+ */
+ @NonNull
+ public Builder setBoundingRectRight(@NonNull Rect boundingRectRight) {
+ mBoundingRectRight.set(boundingRectRight);
+ return this;
+ }
+
+ /**
+ * Set a bounding rectangle for a non-functional area on the display which is located on
+ * the bottom of the screen. If not set, the default value is an empty rectangle.
+ */
+ @NonNull
+ public Builder setBoundingRectBottom(@NonNull Rect boundingRectBottom) {
+ mBoundingRectBottom.set(boundingRectBottom);
+ return this;
+ }
+
+ /**
+ * Set the cutout {@link Path}.
+ *
+ * Note that not support creating/testing multiple display cutouts with setCutoutPath() in
+ * parallel.
+ */
+ @NonNull
+ public Builder setCutoutPath(@NonNull Path cutoutPath) {
+ mCutoutPath = cutoutPath;
+ return this;
+ }
+ }
}