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

Commit dbbebbc3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding source bounds hint to support better PiP transition."

parents cf0341ec 08f81890
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5667,6 +5667,7 @@ package android.app {
    method public int describeContents();
    method public void setActions(java.util.List<android.app.RemoteAction>);
    method public void setAspectRatio(float);
    method public void setSourceRectHint(android.graphics.Rect);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.PictureInPictureArgs> CREATOR;
  }
+1 −0
Original line number Diff line number Diff line
@@ -5859,6 +5859,7 @@ package android.app {
    method public int describeContents();
    method public void setActions(java.util.List<android.app.RemoteAction>);
    method public void setAspectRatio(float);
    method public void setSourceRectHint(android.graphics.Rect);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.PictureInPictureArgs> CREATOR;
  }
+1 −0
Original line number Diff line number Diff line
@@ -5678,6 +5678,7 @@ package android.app {
    method public int describeContents();
    method public void setActions(java.util.List<android.app.RemoteAction>);
    method public void setAspectRatio(float);
    method public void setSourceRectHint(android.graphics.Rect);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.PictureInPictureArgs> CREATOR;
  }
+57 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app;

import android.annotation.Nullable;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;

@@ -35,11 +36,19 @@ public final class PictureInPictureArgs implements Parcelable {
    private Float mAspectRatio;

    /**
     * The set of actions that are associated with this activity when in picture in picture.
     * The set of actions that are associated with this activity when in picture-in-picture.
     */
    @Nullable
    private List<RemoteAction> mUserActions;

    /**
     * The source bounds hint used when entering picture-in-picture, relative to the window bounds.
     * We can use this internally for the transition into picture-in-picture to ensure that a
     * particular source rect is visible throughout the whole transition.
     */
    @Nullable
    private Rect mSourceRectHint;

    PictureInPictureArgs(Parcel in) {
        if (in.readInt() != 0) {
            mAspectRatio = in.readFloat();
@@ -48,6 +57,9 @@ public final class PictureInPictureArgs implements Parcelable {
            mUserActions = new ArrayList<>();
            in.readParcelableList(mUserActions, RemoteAction.class.getClassLoader());
        }
        if (in.readInt() != 0) {
            mSourceRectHint = Rect.CREATOR.createFromParcel(in);
        }
    }

    /**
@@ -79,6 +91,9 @@ public final class PictureInPictureArgs implements Parcelable {
        if (otherArgs.hasSetActions()) {
            mUserActions = otherArgs.mUserActions;
        }
        if (otherArgs.hasSourceBoundsHint()) {
            mSourceRectHint = new Rect(otherArgs.getSourceRectHint());
        }
    }

    /**
@@ -137,9 +152,43 @@ public final class PictureInPictureArgs implements Parcelable {
        return mUserActions != null;
    }

    /**
     * Sets the source bounds hint. These bounds are only used when an activity first enters
     * picture-in-picture, and describe the bounds in window coordinates of activity entering
     * picture-in-picture that will be visible following the transition. For the best effect, these
     * bounds should also match the aspect ratio in the arguments.
     */
    public void setSourceRectHint(Rect launchBounds) {
        if (launchBounds == null) {
            mSourceRectHint = null;
        } else {
            mSourceRectHint = new Rect(launchBounds);
        }
    }

    /**
     * @return the launch bounds
     * @hide
     */
    public Rect getSourceRectHint() {
        return mSourceRectHint;
    }

    /**
     * @return whether there are launch bounds set
     * @hide
     */
    public boolean hasSourceBoundsHint() {
        return mSourceRectHint != null && !mSourceRectHint.isEmpty();
    }

    @Override
    public PictureInPictureArgs clone() {
        return new PictureInPictureArgs(mAspectRatio, mUserActions);
        PictureInPictureArgs args = new PictureInPictureArgs(mAspectRatio, mUserActions);
        if (mSourceRectHint != null) {
            args.setSourceRectHint(mSourceRectHint);
        }
        return args;
    }

    @Override
@@ -161,6 +210,12 @@ public final class PictureInPictureArgs implements Parcelable {
        } else {
            out.writeInt(0);
        }
        if (mSourceRectHint != null) {
            out.writeInt(1);
            mSourceRectHint.writeToParcel(out, 0);
        } else {
            out.writeInt(0);
        }
    }

    public static final Creator<PictureInPictureArgs> CREATOR =
+8 −6
Original line number Diff line number Diff line
@@ -7870,10 +7870,11 @@ public class ActivityManagerService extends IActivityManager.Stub
                    r.pictureInPictureArgs.copyOnlySet(args);
                    final float aspectRatio = r.pictureInPictureArgs.getAspectRatio();
                    final List<RemoteAction> actions = r.pictureInPictureArgs.getActions();
                    final Rect bounds = mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY,
                    final Rect sourceBounds = r.pictureInPictureArgs.getSourceRectHint();
                    final Rect destBounds = mWindowManager.getPictureInPictureBounds(DEFAULT_DISPLAY,
                            aspectRatio);
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, "enterPictureInPictureMode",
                            bounds, true /* moveHomeStackToFront */);
                    mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, destBounds,
                            true /* moveHomeStackToFront */, "enterPictureInPictureMode");
                    final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID);
                    stack.setPictureInPictureAspectRatio(aspectRatio);
                    stack.setPictureInPictureActions(actions);
@@ -10525,7 +10526,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public void resizeStack(int stackId, Rect bounds, boolean allowResizeInDockedMode,
    public void resizeStack(int stackId, Rect destBounds, boolean allowResizeInDockedMode,
            boolean preserveWindows, boolean animate, int animationDuration) {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()");
        long ident = Binder.clearCallingIdentity();
@@ -10535,13 +10536,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                    if (stackId == PINNED_STACK_ID) {
                        final PinnedActivityStack pinnedStack =
                                mStackSupervisor.getStack(PINNED_STACK_ID);
                        pinnedStack.animateResizePinnedStack(bounds, animationDuration);
                        pinnedStack.animateResizePinnedStack(null /* sourceBounds */, destBounds,
                                animationDuration);
                    } else {
                        throw new IllegalArgumentException("Stack: " + stackId
                                + " doesn't support animated resize.");
                    }
                } else {
                    mStackSupervisor.resizeStackLocked(stackId, bounds, null /* tempTaskBounds */,
                    mStackSupervisor.resizeStackLocked(stackId, destBounds, null /* tempTaskBounds */,
                            null /* tempTaskInsetBounds */, preserveWindows,
                            allowResizeInDockedMode, !DEFER_RESUME);
                }
Loading