1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app;
18 
19 import android.annotation.NonNull;
20 import android.annotation.TestApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import java.util.Objects;
25 
26 /**
27  * Used by {@link Activity#onPictureInPictureUiStateChanged(PictureInPictureUiState)}.
28  */
29 public final class PictureInPictureUiState implements Parcelable {
30 
31     private boolean mIsStashed;
32 
33     /** {@hide} */
PictureInPictureUiState(Parcel in)34     PictureInPictureUiState(Parcel in) {
35         mIsStashed = in.readBoolean();
36     }
37 
38     /** {@hide} */
39     @TestApi
PictureInPictureUiState(boolean isStashed)40     public PictureInPictureUiState(boolean isStashed) {
41         mIsStashed = isStashed;
42     }
43 
44     /**
45      * Returns whether Picture-in-Picture is stashed or not. A stashed PiP means it is only
46      * partially visible to the user, with some parts of it being off-screen. This is usually
47      * an UI state that is triggered by the user, such as flinging the PiP to the edge or letting go
48      * of PiP while dragging partially off-screen.
49      *
50      * Developers can use this in conjunction with
51      * {@link Activity#onPictureInPictureUiStateChanged(PictureInPictureUiState)} to get a signal
52      * when the PiP stash state has changed. For example, if the state changed from {@code false} to
53      * {@code true}, developers can choose to temporarily pause video playback if PiP is of video
54      * content. Vice versa, if changing from {@code true} to {@code false} and video content is
55      * paused, developers can resumevideo playback.
56      *
57      * @see <a href="http://developer.android.com/about/versions/12/features/pip-improvements">
58      *     Picture in Picture (PiP) improvements</a>
59      */
isStashed()60     public boolean isStashed() {
61         return mIsStashed;
62     }
63 
64     @Override
equals(Object o)65     public boolean equals(Object o) {
66         if (this == o) return true;
67         if (!(o instanceof PictureInPictureUiState)) return false;
68         PictureInPictureUiState that = (PictureInPictureUiState) o;
69         return Objects.equals(mIsStashed, that.mIsStashed);
70     }
71 
72     @Override
hashCode()73     public int hashCode() {
74         return Objects.hash(mIsStashed);
75     }
76 
77     @Override
describeContents()78     public int describeContents() {
79         return 0;
80     }
81 
82     @Override
writeToParcel(@onNull Parcel out, int flags)83     public void writeToParcel(@NonNull Parcel out, int flags) {
84         out.writeBoolean(mIsStashed);
85     }
86 
87     public static final @android.annotation.NonNull Creator<PictureInPictureUiState> CREATOR =
88             new Creator<PictureInPictureUiState>() {
89                 public PictureInPictureUiState createFromParcel(Parcel in) {
90                     return new PictureInPictureUiState(in);
91                 }
92                 public PictureInPictureUiState[] newArray(int size) {
93                     return new PictureInPictureUiState[size];
94                 }
95             };
96 }
97