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 static android.window.TransitionInfo.AnimationOptions.DEFAULT_ANIMATION_RESOURCES_ID; 20 21 import android.annotation.AnimRes; 22 import android.annotation.ColorInt; 23 import android.annotation.NonNull; 24 import android.annotation.Nullable; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 28 import java.util.Objects; 29 30 /** 31 * Data object for animation related override of TaskFragment. 32 * @hide 33 */ 34 public final class TaskFragmentAnimationParams implements Parcelable { 35 36 /** The default {@link TaskFragmentAnimationParams} to use when there is no app override. */ 37 public static final TaskFragmentAnimationParams DEFAULT = 38 new TaskFragmentAnimationParams.Builder().build(); 39 40 /** 41 * The default value for animation background color, which means to use the theme window 42 * background color. 43 */ 44 @ColorInt 45 public static final int DEFAULT_ANIMATION_BACKGROUND_COLOR = 0; 46 47 @ColorInt 48 private final int mAnimationBackgroundColor; 49 50 @AnimRes 51 private final int mOpenAnimationResId; 52 53 @AnimRes 54 private final int mChangeAnimationResId; 55 56 @AnimRes 57 private final int mCloseAnimationResId; 58 TaskFragmentAnimationParams(@olorInt int animationBackgroundColor, @AnimRes int openAnimationResId, @AnimRes int changeAnimationResId, @AnimRes int closeAnimationResId)59 private TaskFragmentAnimationParams(@ColorInt int animationBackgroundColor, 60 @AnimRes int openAnimationResId, @AnimRes int changeAnimationResId, 61 @AnimRes int closeAnimationResId) { 62 mAnimationBackgroundColor = animationBackgroundColor; 63 mOpenAnimationResId = openAnimationResId; 64 mChangeAnimationResId = changeAnimationResId; 65 mCloseAnimationResId = closeAnimationResId; 66 } 67 68 /** 69 * The {@link ColorInt} to use for the background during the animation with this TaskFragment if 70 * the animation requires a background. 71 * 72 * The default value is {@code 0}, which is to use the theme window background. 73 */ 74 @ColorInt getAnimationBackgroundColor()75 public int getAnimationBackgroundColor() { 76 return mAnimationBackgroundColor; 77 } 78 79 /** 80 * Returns the resources ID of open animation that applies to this TaskFragment. 81 * <p> 82 * The default value is {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system 83 * default animation. 84 */ 85 @AnimRes getOpenAnimationResId()86 public int getOpenAnimationResId() { 87 return mOpenAnimationResId; 88 } 89 90 /** 91 * Returns the resources ID of change animation that applies to this TaskFragment. 92 * <p> 93 * The default value is {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system 94 * default animation. 95 */ 96 @AnimRes getChangeAnimationResId()97 public int getChangeAnimationResId() { 98 return mChangeAnimationResId; 99 } 100 101 /** 102 * Returns the resources ID of close animation that applies to this TaskFragment. 103 * <p> 104 * The default value is {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system 105 * default animation. 106 */ 107 @AnimRes getCloseAnimationResId()108 public int getCloseAnimationResId() { 109 return mCloseAnimationResId; 110 } 111 TaskFragmentAnimationParams(Parcel in)112 private TaskFragmentAnimationParams(Parcel in) { 113 mAnimationBackgroundColor = in.readInt(); 114 mOpenAnimationResId = in.readInt(); 115 mChangeAnimationResId = in.readInt(); 116 mCloseAnimationResId = in.readInt(); 117 } 118 119 @Override writeToParcel(@onNull Parcel dest, int flags)120 public void writeToParcel(@NonNull Parcel dest, int flags) { 121 dest.writeInt(mAnimationBackgroundColor); 122 dest.writeInt(mOpenAnimationResId); 123 dest.writeInt(mChangeAnimationResId); 124 dest.writeInt(mCloseAnimationResId); 125 } 126 127 @NonNull 128 public static final Creator<TaskFragmentAnimationParams> CREATOR = 129 new Creator<TaskFragmentAnimationParams>() { 130 @Override 131 public TaskFragmentAnimationParams createFromParcel(Parcel in) { 132 return new TaskFragmentAnimationParams(in); 133 } 134 135 @Override 136 public TaskFragmentAnimationParams[] newArray(int size) { 137 return new TaskFragmentAnimationParams[size]; 138 } 139 }; 140 141 @Override toString()142 public String toString() { 143 return "TaskFragmentAnimationParams{" 144 + " animationBgColor=" + Integer.toHexString(mAnimationBackgroundColor) 145 + " openAnimResId=" + mOpenAnimationResId 146 + " changeAnimResId=" + mChangeAnimationResId 147 + " closeAnimResId=" + mCloseAnimationResId 148 + "}"; 149 } 150 151 @Override hashCode()152 public int hashCode() { 153 return Objects.hash(mAnimationBackgroundColor, mOpenAnimationResId, mChangeAnimationResId, 154 mCloseAnimationResId); 155 } 156 157 @Override equals(@ullable Object obj)158 public boolean equals(@Nullable Object obj) { 159 if (!(obj instanceof TaskFragmentAnimationParams other)) { 160 return false; 161 } 162 return mAnimationBackgroundColor == other.mAnimationBackgroundColor 163 && mOpenAnimationResId == other.mOpenAnimationResId 164 && mChangeAnimationResId == other.mChangeAnimationResId 165 && mCloseAnimationResId == other.mCloseAnimationResId; 166 } 167 168 /** 169 * Returns {@code true} if one of {@link #getOpenAnimationResId()}, 170 * {@link #getChangeAnimationResId()} or {@link #getCloseAnimationResId()} is specified. 171 */ hasOverrideAnimation()172 public boolean hasOverrideAnimation() { 173 return mOpenAnimationResId != DEFAULT_ANIMATION_RESOURCES_ID 174 || mChangeAnimationResId != DEFAULT_ANIMATION_BACKGROUND_COLOR 175 || mCloseAnimationResId != DEFAULT_ANIMATION_RESOURCES_ID; 176 } 177 178 @Override describeContents()179 public int describeContents() { 180 return 0; 181 } 182 183 /** Builder to construct the {@link TaskFragmentAnimationParams}. */ 184 public static final class Builder { 185 186 @ColorInt 187 private int mAnimationBackgroundColor = DEFAULT_ANIMATION_BACKGROUND_COLOR; 188 189 @AnimRes 190 private int mOpenAnimationResId = DEFAULT_ANIMATION_RESOURCES_ID; 191 192 @AnimRes 193 private int mChangeAnimationResId = DEFAULT_ANIMATION_RESOURCES_ID; 194 195 @AnimRes 196 private int mCloseAnimationResId = DEFAULT_ANIMATION_RESOURCES_ID; 197 198 /** 199 * Sets the {@link ColorInt} to use for the background during the animation with this 200 * TaskFragment if the animation requires a background. The default value is 201 * {@link #DEFAULT_ANIMATION_BACKGROUND_COLOR}, which is to use the theme window background 202 * color. 203 * 204 * @param color a packed color int, {@code AARRGGBB}, for the animation background color. 205 * @return this {@link Builder}. 206 */ 207 @NonNull setAnimationBackgroundColor(@olorInt int color)208 public Builder setAnimationBackgroundColor(@ColorInt int color) { 209 mAnimationBackgroundColor = color; 210 return this; 211 } 212 213 /** 214 * Sets the open animation resources ID this TaskFragment. The default value is 215 * {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system default animation. 216 * 217 * @param resId the open animation resources ID. 218 * @return this {@link Builder}. 219 */ 220 @NonNull setOpenAnimationResId(@nimRes int resId)221 public Builder setOpenAnimationResId(@AnimRes int resId) { 222 mOpenAnimationResId = resId; 223 return this; 224 } 225 226 /** 227 * Sets the change animation resources ID this TaskFragment. The default value is 228 * {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system default animation. 229 * 230 * @param resId the change animation resources ID. 231 * @return this {@link Builder}. 232 */ 233 @NonNull setChangeAnimationResId(@nimRes int resId)234 public Builder setChangeAnimationResId(@AnimRes int resId) { 235 mChangeAnimationResId = resId; 236 return this; 237 } 238 239 /** 240 * Sets the close animation resources ID this TaskFragment. The default value is 241 * {@link DEFAULT_ANIMATION_RESOURCES_ID}, which is to use the system default animation. 242 * 243 * @param resId the close animation resources ID. 244 * @return this {@link Builder}. 245 */ 246 @NonNull setCloseAnimationResId(@nimRes int resId)247 public Builder setCloseAnimationResId(@AnimRes int resId) { 248 mCloseAnimationResId = resId; 249 return this; 250 } 251 252 /** Constructs the {@link TaskFragmentAnimationParams}. */ 253 @NonNull build()254 public TaskFragmentAnimationParams build() { 255 return new TaskFragmentAnimationParams(mAnimationBackgroundColor, 256 mOpenAnimationResId, mChangeAnimationResId, mCloseAnimationResId); 257 } 258 } 259 } 260