• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.window;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.IBinder;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.Objects;
29 
30 /**
31  * Data object of params for TaskFragment related {@link WindowContainerTransaction} operation.
32  *
33  * @see WindowContainerTransaction#setTaskFragmentOperation(IBinder, TaskFragmentOperation).
34  * @hide
35  */
36 // TODO(b/263436063): move other TaskFragment related operation here.
37 public final class TaskFragmentOperation implements Parcelable {
38 
39     /** Sets the {@link TaskFragmentAnimationParams} for the given TaskFragment. */
40     public static final int OP_TYPE_SET_ANIMATION_PARAMS = 0;
41 
42     @IntDef(prefix = { "OP_TYPE_" }, value = {
43             OP_TYPE_SET_ANIMATION_PARAMS
44     })
45     @Retention(RetentionPolicy.SOURCE)
46     @interface OperationType {}
47 
48     @OperationType
49     private final int mOpType;
50 
51     @Nullable
52     private final TaskFragmentAnimationParams mAnimationParams;
53 
TaskFragmentOperation(@perationType int opType, @Nullable TaskFragmentAnimationParams animationParams)54     private TaskFragmentOperation(@OperationType int opType,
55             @Nullable TaskFragmentAnimationParams animationParams) {
56         mOpType = opType;
57         mAnimationParams = animationParams;
58     }
59 
TaskFragmentOperation(Parcel in)60     private TaskFragmentOperation(Parcel in) {
61         mOpType = in.readInt();
62         mAnimationParams = in.readTypedObject(TaskFragmentAnimationParams.CREATOR);
63     }
64 
65     @Override
writeToParcel(@onNull Parcel dest, int flags)66     public void writeToParcel(@NonNull Parcel dest, int flags) {
67         dest.writeInt(mOpType);
68         dest.writeTypedObject(mAnimationParams, flags);
69     }
70 
71     @NonNull
72     public static final Creator<TaskFragmentOperation> CREATOR =
73             new Creator<TaskFragmentOperation>() {
74                 @Override
75                 public TaskFragmentOperation createFromParcel(Parcel in) {
76                     return new TaskFragmentOperation(in);
77                 }
78 
79                 @Override
80                 public TaskFragmentOperation[] newArray(int size) {
81                     return new TaskFragmentOperation[size];
82                 }
83             };
84 
85     /**
86      * Gets the {@link OperationType} of this {@link TaskFragmentOperation}.
87      */
88     @OperationType
getOpType()89     public int getOpType() {
90         return mOpType;
91     }
92 
93     /**
94      * Gets the animation related override of TaskFragment.
95      */
96     @Nullable
getAnimationParams()97     public TaskFragmentAnimationParams getAnimationParams() {
98         return mAnimationParams;
99     }
100 
101     @Override
toString()102     public String toString() {
103         final StringBuilder sb = new StringBuilder();
104         sb.append("TaskFragmentOperation{ opType=").append(mOpType);
105         if (mAnimationParams != null) {
106             sb.append(", animationParams=").append(mAnimationParams);
107         }
108 
109         sb.append('}');
110         return sb.toString();
111     }
112 
113     @Override
hashCode()114     public int hashCode() {
115         int result = mOpType;
116         result = result * 31 + mAnimationParams.hashCode();
117         return result;
118     }
119 
120     @Override
equals(@ullable Object obj)121     public boolean equals(@Nullable Object obj) {
122         if (!(obj instanceof TaskFragmentOperation)) {
123             return false;
124         }
125         final TaskFragmentOperation other = (TaskFragmentOperation) obj;
126         return mOpType == other.mOpType
127                 && Objects.equals(mAnimationParams, other.mAnimationParams);
128     }
129 
130     @Override
describeContents()131     public int describeContents() {
132         return 0;
133     }
134 
135     /** Builder to construct the {@link TaskFragmentOperation}. */
136     public static final class Builder {
137 
138         @OperationType
139         private final int mOpType;
140 
141         @Nullable
142         private TaskFragmentAnimationParams mAnimationParams;
143 
144         /**
145          * @param opType the {@link OperationType} of this {@link TaskFragmentOperation}.
146          */
Builder(@perationType int opType)147         public Builder(@OperationType int opType) {
148             mOpType = opType;
149         }
150 
151         /**
152          * Sets the {@link TaskFragmentAnimationParams} for the given TaskFragment.
153          */
154         @NonNull
setAnimationParams(@ullable TaskFragmentAnimationParams animationParams)155         public Builder setAnimationParams(@Nullable TaskFragmentAnimationParams animationParams) {
156             mAnimationParams = animationParams;
157             return this;
158         }
159 
160         /**
161          * Constructs the {@link TaskFragmentOperation}.
162          */
163         @NonNull
build()164         public TaskFragmentOperation build() {
165             return new TaskFragmentOperation(mOpType, mAnimationParams);
166         }
167     }
168 }
169