PictureInPictureParamsCompat


public final class PictureInPictureParamsCompat


Helper class to access the framework android.app.PictureInPictureParams.

Builder is offered for a fluent API.

Summary

Nested types

Builder class for PictureInPictureParamsCompat.

Public constructors

PictureInPictureParamsCompat(
    boolean isEnabled,
    Rational aspectRatio,
    @NonNull List<@NonNull RemoteAction> actions,
    Rect sourceRectHint,
    boolean isSeamlessResizeEnabled,
    RemoteAction closeAction,
    Rational expandedAspectRatio,
    CharSequence title,
    CharSequence subTitle
)

Public methods

final @NonNull List<@NonNull RemoteAction>

Sets the user actions.

final Rational

Sets the aspect ratio.

final RemoteAction

Sets a close action that should be invoked before the default close PiP action.

final Rational

Sets the aspect ratio for the expanded picture-in-picture mode.

final Rect

Sets the window-coordinate bounds of an activity transitioning to picture-in-picture.

final CharSequence

Sets a subtitle for the picture-in-picture window, which may be displayed by the system to give the user more detailed information about what this PIP is displaying.

final CharSequence

Sets a title for the picture-in-picture window, which may be displayed by the system to give the user information about what this PIP is generally being used for.

final boolean

This field indicates the PiP-able state of the application, and it will be translated to PictureInPictureParams.isAutoEnterEnabled on API 31+.

final boolean

Sets whether the system can seamlessly resize the window while the activity is in picture-in-picture mode.

Public constructors

PictureInPictureParamsCompat

public PictureInPictureParamsCompat(
    boolean isEnabled,
    Rational aspectRatio,
    @NonNull List<@NonNull RemoteAction> actions,
    Rect sourceRectHint,
    boolean isSeamlessResizeEnabled,
    RemoteAction closeAction,
    Rational expandedAspectRatio,
    CharSequence title,
    CharSequence subTitle
)

Public methods

getActions

public final @NonNull List<@NonNull RemoteActiongetActions()

Sets the user actions. If there are more than ComponentActivity.getMaxNumPictureInPictureActions actions, then the input list will be truncated to that number.

Compatibility notes: this field is used on API 26+

getAspectRatio

public final Rational getAspectRatio()

Sets the aspect ratio. This aspect ratio is defined as the desired width / height, and does not change upon device rotation.

Compatibility notes: this field is used on API 26+

getCloseAction

public final RemoteAction getCloseAction()

Sets a close action that should be invoked before the default close PiP action. The custom action must close the activity quickly using ComponentActivity.finish. Otherwise, the system will forcibly close the PiP as if no custom close action was provided.

If the action matches one set via actions it may be shown in place of that custom action in the menu.

Compatibility notes: this field is used on API 33+

getExpandedAspectRatio

public final Rational getExpandedAspectRatio()

Sets the aspect ratio for the expanded picture-in-picture mode. The aspect ratio is defined as the desired width / height. The aspect ratio cannot be changed from horizontal to vertical or vertical to horizontal while the PIP is shown. Any such changes will be ignored.

Setting the expanded ratio shows the activity's support for expanded mode.

Compatibility notes: this field is used on API 33+

getSourceRectHint

public final Rect getSourceRectHint()

Sets the window-coordinate bounds of an activity transitioning to picture-in-picture. The bounds is the area of an activity that will be visible in the transition to picture-in-picture mode. For the best effect, these bounds should also match the aspect ratio in the arguments.

In Android 12+ these bounds are also reused to improve the exit transition from picture-in-picture mode. See the Picture-in-Picture doc for more details.

Compatibility notes: this field is used on API 26+

getSubTitle

public final CharSequence getSubTitle()

Sets a subtitle for the picture-in-picture window, which may be displayed by the system to give the user more detailed information about what this PIP is displaying.

Compatibility notes: this field is used on API 33+

getTitle

public final CharSequence getTitle()

Sets a title for the picture-in-picture window, which may be displayed by the system to give the user information about what this PIP is generally being used for.

Compatibility notes: this field is used on API 33+

isEnabled

public final boolean isEnabled()

This field indicates the PiP-able state of the application, and it will be translated to PictureInPictureParams.isAutoEnterEnabled on API 31+.

isSeamlessResizeEnabled

public final boolean isSeamlessResizeEnabled()

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 false, system will perform transitions to overcome the artifacts due to resize.

Compatibility notes: this field is used on API 31+