summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/current.txt1
-rw-r--r--core/api/test-current.txt1
-rw-r--r--core/java/android/app/PictureInPictureParams.java84
3 files changed, 73 insertions, 13 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index cf73689a8a4b..471f4c9fd384 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -6216,6 +6216,7 @@ package android.app {
method public android.app.PictureInPictureParams.Builder setActions(java.util.List<android.app.RemoteAction>);
method public android.app.PictureInPictureParams.Builder setAspectRatio(android.util.Rational);
method @NonNull public android.app.PictureInPictureParams.Builder setAutoEnterEnabled(boolean);
+ method @NonNull public android.app.PictureInPictureParams.Builder setSeamlessResizeEnabled(boolean);
method public android.app.PictureInPictureParams.Builder setSourceRectHint(android.graphics.Rect);
}
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 12531976d90e..d2941c3d1119 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -283,6 +283,7 @@ package android.app {
method public java.util.List<android.app.RemoteAction> getActions();
method public float getAspectRatio();
method public android.graphics.Rect getSourceRectHint();
+ method public boolean isSeamlessResizeEnabled();
}
public class StatusBarManager {
diff --git a/core/java/android/app/PictureInPictureParams.java b/core/java/android/app/PictureInPictureParams.java
index 29c9c67e12c3..ea7eab2a2877 100644
--- a/core/java/android/app/PictureInPictureParams.java
+++ b/core/java/android/app/PictureInPictureParams.java
@@ -48,7 +48,9 @@ public final class PictureInPictureParams implements Parcelable {
@Nullable
private Rect mSourceRectHint;
- private boolean mAutoEnterEnabled;
+ private Boolean mAutoEnterEnabled;
+
+ private Boolean mSeamlessResizeEnabled;
/**
* Sets the aspect ratio. This aspect ratio is defined as the desired width / height, and
@@ -113,7 +115,7 @@ public final class PictureInPictureParams implements Parcelable {
*
* If true, {@link Activity#onPictureInPictureRequested()} will never be called.
*
- * This property is false by default.
+ * This property is {@code false} by default.
* @param autoEnterEnabled {@code true} if the system will automatically put the activity
* in picture-in-picture mode.
*
@@ -126,6 +128,23 @@ public final class PictureInPictureParams implements Parcelable {
}
/**
+ * Sets whether the system can seamlessly resize the window while the activity is in
+ * picture-in-picture mode. This should normally be the case for video content and
+ * when it's set to {@code false}, system will perform transitions to overcome the
+ * artifacts due to resize.
+ *
+ * This property is {@code true} by default for backwards compatibility.
+ * @param seamlessResizeEnabled {@code true} if the system can seamlessly resize the window
+ * while activity is in picture-in-picture mode.
+ * @return this builder instance.
+ */
+ @NonNull
+ public Builder setSeamlessResizeEnabled(boolean seamlessResizeEnabled) {
+ mSeamlessResizeEnabled = seamlessResizeEnabled;
+ return this;
+ }
+
+ /**
* @return an immutable {@link PictureInPictureParams} to be used when entering or updating
* the activity in picture-in-picture.
*
@@ -134,7 +153,7 @@ public final class PictureInPictureParams implements Parcelable {
*/
public PictureInPictureParams build() {
PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, mUserActions,
- mSourceRectHint, mAutoEnterEnabled);
+ mSourceRectHint, mAutoEnterEnabled, mSeamlessResizeEnabled);
return params;
}
}
@@ -161,8 +180,16 @@ public final class PictureInPictureParams implements Parcelable {
/**
* Whether the system is allowed to automatically put the activity in picture-in-picture mode.
+ * {@link #isAutoEnterEnabled()} defaults to {@code false} if this is not set.
+ */
+ private Boolean mAutoEnterEnabled;
+
+ /**
+ * Whether system can seamlessly resize the window when activity is in picture-in-picture mode.
+ * {@link #isSeamlessResizeEnabled()} defaults to {@code true} if this is not set for
+ * backwards compatibility.
*/
- private boolean mAutoEnterEnabled;
+ private Boolean mSeamlessResizeEnabled;
/** {@hide} */
PictureInPictureParams() {
@@ -183,15 +210,19 @@ public final class PictureInPictureParams implements Parcelable {
if (in.readInt() != 0) {
mAutoEnterEnabled = in.readBoolean();
}
+ if (in.readInt() != 0) {
+ mSeamlessResizeEnabled = in.readBoolean();
+ }
}
/** {@hide} */
PictureInPictureParams(Rational aspectRatio, List<RemoteAction> actions,
- Rect sourceRectHint, boolean autoEnterEnabled) {
+ Rect sourceRectHint, Boolean autoEnterEnabled, Boolean seamlessResizeEnabled) {
mAspectRatio = aspectRatio;
mUserActions = actions;
mSourceRectHint = sourceRectHint;
mAutoEnterEnabled = autoEnterEnabled;
+ mSeamlessResizeEnabled = seamlessResizeEnabled;
}
/**
@@ -201,7 +232,7 @@ public final class PictureInPictureParams implements Parcelable {
public PictureInPictureParams(PictureInPictureParams other) {
this(other.mAspectRatio, other.mUserActions,
other.hasSourceBoundsHint() ? new Rect(other.getSourceRectHint()) : null,
- other.mAutoEnterEnabled);
+ other.mAutoEnterEnabled, other.mSeamlessResizeEnabled);
}
/**
@@ -218,7 +249,12 @@ public final class PictureInPictureParams implements Parcelable {
if (otherArgs.hasSourceBoundsHint()) {
mSourceRectHint = new Rect(otherArgs.getSourceRectHint());
}
- mAutoEnterEnabled = otherArgs.mAutoEnterEnabled;
+ if (otherArgs.mAutoEnterEnabled != null) {
+ mAutoEnterEnabled = otherArgs.mAutoEnterEnabled;
+ }
+ if (otherArgs.mSeamlessResizeEnabled != null) {
+ mSeamlessResizeEnabled = otherArgs.mSeamlessResizeEnabled;
+ }
}
/**
@@ -295,7 +331,16 @@ public final class PictureInPictureParams implements Parcelable {
* @hide
*/
public boolean isAutoEnterEnabled() {
- return mAutoEnterEnabled;
+ return mAutoEnterEnabled == null ? false : mAutoEnterEnabled;
+ }
+
+ /**
+ * @return whether seamless resize is enabled.
+ * @hide
+ */
+ @TestApi
+ public boolean isSeamlessResizeEnabled() {
+ return mSeamlessResizeEnabled == null ? true : mSeamlessResizeEnabled;
}
/**
@@ -304,7 +349,7 @@ public final class PictureInPictureParams implements Parcelable {
*/
public boolean empty() {
return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio()
- && !mAutoEnterEnabled;
+ && mAutoEnterEnabled != null && mSeamlessResizeEnabled != null;
}
@Override
@@ -312,7 +357,8 @@ public final class PictureInPictureParams implements Parcelable {
if (this == o) return true;
if (!(o instanceof PictureInPictureParams)) return false;
PictureInPictureParams that = (PictureInPictureParams) o;
- return mAutoEnterEnabled == that.mAutoEnterEnabled
+ return Objects.equals(mAutoEnterEnabled, that.mAutoEnterEnabled)
+ && Objects.equals(mSeamlessResizeEnabled, that.mSeamlessResizeEnabled)
&& Objects.equals(mAspectRatio, that.mAspectRatio)
&& Objects.equals(mUserActions, that.mUserActions)
&& Objects.equals(mSourceRectHint, that.mSourceRectHint);
@@ -320,7 +366,8 @@ public final class PictureInPictureParams implements Parcelable {
@Override
public int hashCode() {
- return Objects.hash(mAspectRatio, mUserActions, mSourceRectHint, mAutoEnterEnabled);
+ return Objects.hash(mAspectRatio, mUserActions, mSourceRectHint,
+ mAutoEnterEnabled, mSeamlessResizeEnabled);
}
@Override
@@ -349,8 +396,18 @@ public final class PictureInPictureParams implements Parcelable {
} else {
out.writeInt(0);
}
- out.writeInt(1);
- out.writeBoolean(mAutoEnterEnabled);
+ if (mAutoEnterEnabled != null) {
+ out.writeInt(1);
+ out.writeBoolean(mAutoEnterEnabled);
+ } else {
+ out.writeInt(0);
+ }
+ if (mSeamlessResizeEnabled != null) {
+ out.writeInt(1);
+ out.writeBoolean(mSeamlessResizeEnabled);
+ } else {
+ out.writeInt(0);
+ }
}
@Override
@@ -360,6 +417,7 @@ public final class PictureInPictureParams implements Parcelable {
+ " sourceRectHint=" + getSourceRectHint()
+ " hasSetActions=" + hasSetActions()
+ " isAutoPipEnabled=" + isAutoEnterEnabled()
+ + " isSeamlessResizeEnabled=" + isSeamlessResizeEnabled()
+ ")";
}