| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.window; |
| 18 |
|
| 19 |
import static android.app.ActivityOptions.ANIM_CLIP_REVEAL; |
| 20 |
import static android.app.ActivityOptions.ANIM_CUSTOM; |
| 21 |
import static android.app.ActivityOptions.ANIM_FROM_STYLE; |
| 22 |
import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS; |
| 23 |
import static android.app.ActivityOptions.ANIM_SCALE_UP; |
| 24 |
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN; |
| 25 |
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP; |
| 26 |
import static android.app.WindowConfiguration.ROTATION_UNDEFINED; |
| 27 |
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED; |
| 28 |
import static android.view.WindowManager.TRANSIT_CHANGE; |
| 29 |
import static android.view.WindowManager.TRANSIT_CLOSE; |
| 30 |
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY; |
| 31 |
import static android.view.WindowManager.TRANSIT_NONE; |
| 32 |
import static android.view.WindowManager.TRANSIT_OPEN; |
| 33 |
import static android.view.WindowManager.TRANSIT_TO_BACK; |
| 34 |
import static android.view.WindowManager.TRANSIT_TO_FRONT; |
| 35 |
import static android.view.WindowManager.TransitionFlags; |
| 36 |
import static android.view.WindowManager.TransitionType; |
| 37 |
import static android.view.WindowManager.transitTypeToString; |
| 38 |
|
| 39 |
import android.annotation.ColorInt; |
| 40 |
import android.annotation.IntDef; |
| 41 |
import android.annotation.NonNull; |
| 42 |
import android.annotation.Nullable; |
| 43 |
import android.app.ActivityManager; |
| 44 |
import android.graphics.Point; |
| 45 |
import android.graphics.Rect; |
| 46 |
import android.hardware.HardwareBuffer; |
| 47 |
import android.os.Parcel; |
| 48 |
import android.os.Parcelable; |
| 49 |
import android.view.Surface; |
| 50 |
import android.view.SurfaceControl; |
| 51 |
import android.view.WindowManager; |
| 52 |
|
| 53 |
import java.util.ArrayList; |
| 54 |
import java.util.List; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public final class TransitionInfo implements Parcelable { |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
@IntDef(prefix = { "TRANSIT_" }, value = { |
| 67 |
TRANSIT_NONE, |
| 68 |
TRANSIT_OPEN, |
| 69 |
TRANSIT_CLOSE, |
| 70 |
|
| 71 |
TRANSIT_TO_FRONT, |
| 72 |
TRANSIT_TO_BACK, |
| 73 |
TRANSIT_CHANGE |
| 74 |
}) |
| 75 |
public @interface TransitionMode {} |
| 76 |
|
| 77 |
|
| 78 |
public static final int FLAG_NONE = 0; |
| 79 |
|
| 80 |
|
| 81 |
public static final int FLAG_SHOW_WALLPAPER = 1; |
| 82 |
|
| 83 |
|
| 84 |
public static final int FLAG_IS_WALLPAPER = 1 << 1; |
| 85 |
|
| 86 |
|
| 87 |
public static final int FLAG_TRANSLUCENT = 1 << 2; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public static final int FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT = 1 << 3; |
| 92 |
|
| 93 |
|
| 94 |
public static final int FLAG_IS_VOICE_INTERACTION = 1 << 4; |
| 95 |
|
| 96 |
|
| 97 |
public static final int FLAG_IS_DISPLAY = 1 << 5; |
| 98 |
|
| 99 |
|
| 100 |
public static final int FLAG_OCCLUDES_KEYGUARD = 1 << 6; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static final int FLAG_DISPLAY_HAS_ALERT_WINDOWS = 1 << 7; |
| 109 |
|
| 110 |
|
| 111 |
public static final int FLAG_IS_INPUT_METHOD = 1 << 8; |
| 112 |
|
| 113 |
|
| 114 |
public static final int FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY = 1 << 9; |
| 115 |
|
| 116 |
|
| 117 |
public static final int FLAG_FILLS_TASK = 1 << 10; |
| 118 |
|
| 119 |
|
| 120 |
public static final int FLAG_WILL_IME_SHOWN = 1 << 11; |
| 121 |
|
| 122 |
|
| 123 |
public static final int FLAG_CROSS_PROFILE_OWNER_THUMBNAIL = 1 << 12; |
| 124 |
|
| 125 |
|
| 126 |
public static final int FLAG_CROSS_PROFILE_WORK_THUMBNAIL = 1 << 13; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public static final int FLAG_IS_BEHIND_STARTING_WINDOW = 1 << 14; |
| 134 |
|
| 135 |
|
| 136 |
public static final int FLAG_IS_OCCLUDED = 1 << 15; |
| 137 |
|
| 138 |
|
| 139 |
public static final int FLAG_IS_SYSTEM_WINDOW = 1 << 16; |
| 140 |
|
| 141 |
|
| 142 |
public static final int FLAG_FIRST_CUSTOM = 1 << 17; |
| 143 |
|
| 144 |
|
| 145 |
public static final int FLAGS_IS_NON_APP_WINDOW = |
| 146 |
FLAG_IS_WALLPAPER | FLAG_IS_INPUT_METHOD | FLAG_IS_SYSTEM_WINDOW; |
| 147 |
|
| 148 |
|
| 149 |
@IntDef(prefix = { "FLAG_" }, value = { |
| 150 |
FLAG_NONE, |
| 151 |
FLAG_SHOW_WALLPAPER, |
| 152 |
FLAG_IS_WALLPAPER, |
| 153 |
FLAG_TRANSLUCENT, |
| 154 |
FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT, |
| 155 |
FLAG_IS_VOICE_INTERACTION, |
| 156 |
FLAG_IS_DISPLAY, |
| 157 |
FLAG_OCCLUDES_KEYGUARD, |
| 158 |
FLAG_DISPLAY_HAS_ALERT_WINDOWS, |
| 159 |
FLAG_IS_INPUT_METHOD, |
| 160 |
FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY, |
| 161 |
FLAG_FILLS_TASK, |
| 162 |
FLAG_WILL_IME_SHOWN, |
| 163 |
FLAG_CROSS_PROFILE_OWNER_THUMBNAIL, |
| 164 |
FLAG_CROSS_PROFILE_WORK_THUMBNAIL, |
| 165 |
FLAG_IS_BEHIND_STARTING_WINDOW, |
| 166 |
FLAG_IS_OCCLUDED, |
| 167 |
FLAG_IS_SYSTEM_WINDOW, |
| 168 |
FLAG_FIRST_CUSTOM |
| 169 |
}) |
| 170 |
public @interface ChangeFlags {} |
| 171 |
|
| 172 |
private final @TransitionType int mType; |
| 173 |
private final @TransitionFlags int mFlags; |
| 174 |
private final ArrayList<Change> mChanges = new ArrayList<>(); |
| 175 |
|
| 176 |
private SurfaceControl mRootLeash; |
| 177 |
private final Point mRootOffset = new Point(); |
| 178 |
|
| 179 |
private AnimationOptions mOptions; |
| 180 |
|
| 181 |
|
| 182 |
public TransitionInfo(@TransitionType int type, @TransitionFlags int flags) { |
| 183 |
mType = type; |
| 184 |
mFlags = flags; |
| 185 |
} |
| 186 |
|
| 187 |
private TransitionInfo(Parcel in) { |
| 188 |
mType = in.readInt(); |
| 189 |
mFlags = in.readInt(); |
| 190 |
in.readTypedList(mChanges, Change.CREATOR); |
| 191 |
mRootLeash = new SurfaceControl(); |
| 192 |
mRootLeash.readFromParcel(in); |
| 193 |
mRootOffset.readFromParcel(in); |
| 194 |
mOptions = in.readTypedObject(AnimationOptions.CREATOR); |
| 195 |
} |
| 196 |
|
| 197 |
@Override |
| 198 |
|
| 199 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 200 |
dest.writeInt(mType); |
| 201 |
dest.writeInt(mFlags); |
| 202 |
dest.writeTypedList(mChanges); |
| 203 |
mRootLeash.writeToParcel(dest, flags); |
| 204 |
mRootOffset.writeToParcel(dest, flags); |
| 205 |
dest.writeTypedObject(mOptions, flags); |
| 206 |
} |
| 207 |
|
| 208 |
@NonNull |
| 209 |
public static final Creator<TransitionInfo> CREATOR = |
| 210 |
new Creator<TransitionInfo>() { |
| 211 |
@Override |
| 212 |
public TransitionInfo createFromParcel(Parcel in) { |
| 213 |
return new TransitionInfo(in); |
| 214 |
} |
| 215 |
|
| 216 |
@Override |
| 217 |
public TransitionInfo[] newArray(int size) { |
| 218 |
return new TransitionInfo[size]; |
| 219 |
} |
| 220 |
}; |
| 221 |
|
| 222 |
@Override |
| 223 |
|
| 224 |
public int describeContents() { |
| 225 |
return 0; |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
public void setRootLeash(@NonNull SurfaceControl leash, int offsetLeft, int offsetTop) { |
| 230 |
mRootLeash = leash; |
| 231 |
mRootOffset.set(offsetLeft, offsetTop); |
| 232 |
} |
| 233 |
|
| 234 |
public void setAnimationOptions(AnimationOptions options) { |
| 235 |
mOptions = options; |
| 236 |
} |
| 237 |
|
| 238 |
public @TransitionType int getType() { |
| 239 |
return mType; |
| 240 |
} |
| 241 |
|
| 242 |
public int getFlags() { |
| 243 |
return mFlags; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
@NonNull |
| 253 |
public SurfaceControl getRootLeash() { |
| 254 |
if (mRootLeash == null) { |
| 255 |
throw new IllegalStateException("Trying to get a leash which wasn't set"); |
| 256 |
} |
| 257 |
return mRootLeash; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
@NonNull |
| 262 |
public Point getRootOffset() { |
| 263 |
return mRootOffset; |
| 264 |
} |
| 265 |
|
| 266 |
public AnimationOptions getAnimationOptions() { |
| 267 |
return mOptions; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
@NonNull |
| 275 |
public List<Change> getChanges() { |
| 276 |
return mChanges; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
@Nullable |
| 284 |
public Change getChange(@NonNull WindowContainerToken token) { |
| 285 |
for (int i = mChanges.size() - 1; i >= 0; --i) { |
| 286 |
if (token.equals(mChanges.get(i).mContainer)) { |
| 287 |
return mChanges.get(i); |
| 288 |
} |
| 289 |
} |
| 290 |
return null; |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
public void addChange(@NonNull Change change) { |
| 297 |
mChanges.add(change); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
public boolean isKeyguardGoingAway() { |
| 304 |
return (mFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY) != 0; |
| 305 |
} |
| 306 |
|
| 307 |
@Override |
| 308 |
public String toString() { |
| 309 |
StringBuilder sb = new StringBuilder(); |
| 310 |
sb.append("{t=" + transitTypeToString(mType) + " f=0x" + Integer.toHexString(mFlags) |
| 311 |
+ " ro=" + mRootOffset + " c=["); |
| 312 |
for (int i = 0; i < mChanges.size(); ++i) { |
| 313 |
if (i > 0) { |
| 314 |
sb.append(','); |
| 315 |
} |
| 316 |
sb.append(mChanges.get(i)); |
| 317 |
} |
| 318 |
sb.append("]}"); |
| 319 |
return sb.toString(); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
@NonNull |
| 324 |
public static String modeToString(@TransitionMode int mode) { |
| 325 |
switch(mode) { |
| 326 |
case TRANSIT_NONE: return "NONE"; |
| 327 |
case TRANSIT_OPEN: return "OPEN"; |
| 328 |
case TRANSIT_CLOSE: return "CLOSE"; |
| 329 |
case TRANSIT_TO_FRONT: return "SHOW"; |
| 330 |
case TRANSIT_TO_BACK: return "HIDE"; |
| 331 |
case TRANSIT_CHANGE: return "CHANGE"; |
| 332 |
default: return "<unknown:" + mode + ">"; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
@NonNull |
| 338 |
public static String flagsToString(@ChangeFlags int flags) { |
| 339 |
if (flags == 0) return "NONE"; |
| 340 |
final StringBuilder sb = new StringBuilder(); |
| 341 |
if ((flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 342 |
sb.append("SHOW_WALLPAPER"); |
| 343 |
} |
| 344 |
if ((flags & FLAG_IS_WALLPAPER) != 0) { |
| 345 |
sb.append("IS_WALLPAPER"); |
| 346 |
} |
| 347 |
if ((flags & FLAG_IS_INPUT_METHOD) != 0) { |
| 348 |
sb.append("IS_INPUT_METHOD"); |
| 349 |
} |
| 350 |
if ((flags & FLAG_TRANSLUCENT) != 0) { |
| 351 |
sb.append(sb.length() == 0 ? "" : "|").append("TRANSLUCENT"); |
| 352 |
} |
| 353 |
if ((flags & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) != 0) { |
| 354 |
sb.append(sb.length() == 0 ? "" : "|").append("STARTING_WINDOW_TRANSFER"); |
| 355 |
} |
| 356 |
if ((flags & FLAG_IS_VOICE_INTERACTION) != 0) { |
| 357 |
sb.append(sb.length() == 0 ? "" : "|").append("IS_VOICE_INTERACTION"); |
| 358 |
} |
| 359 |
if ((flags & FLAG_IS_DISPLAY) != 0) { |
| 360 |
sb.append(sb.length() == 0 ? "" : "|").append("IS_DISPLAY"); |
| 361 |
} |
| 362 |
if ((flags & FLAG_OCCLUDES_KEYGUARD) != 0) { |
| 363 |
sb.append(sb.length() == 0 ? "" : "|").append("OCCLUDES_KEYGUARD"); |
| 364 |
} |
| 365 |
if ((flags & FLAG_DISPLAY_HAS_ALERT_WINDOWS) != 0) { |
| 366 |
sb.append(sb.length() == 0 ? "" : "|").append("DISPLAY_HAS_ALERT_WINDOWS"); |
| 367 |
} |
| 368 |
if ((flags & FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY) != 0) { |
| 369 |
sb.append(sb.length() == 0 ? "" : "|").append("IN_TASK_WITH_EMBEDDED_ACTIVITY"); |
| 370 |
} |
| 371 |
if ((flags & FLAG_FILLS_TASK) != 0) { |
| 372 |
sb.append(sb.length() == 0 ? "" : "|").append("FILLS_TASK"); |
| 373 |
} |
| 374 |
if ((flags & FLAG_IS_BEHIND_STARTING_WINDOW) != 0) { |
| 375 |
sb.append(sb.length() == 0 ? "" : "|").append("IS_BEHIND_STARTING_WINDOW"); |
| 376 |
} |
| 377 |
if ((flags & FLAG_IS_OCCLUDED) != 0) { |
| 378 |
sb.append(sb.length() == 0 ? "" : "|").append("IS_OCCLUDED"); |
| 379 |
} |
| 380 |
if ((flags & FLAG_IS_SYSTEM_WINDOW) != 0) { |
| 381 |
sb.append(sb.length() == 0 ? "" : "|").append("FLAG_IS_SYSTEM_WINDOW"); |
| 382 |
} |
| 383 |
if ((flags & FLAG_FIRST_CUSTOM) != 0) { |
| 384 |
sb.append(sb.length() == 0 ? "" : "|").append("FIRST_CUSTOM"); |
| 385 |
} |
| 386 |
return sb.toString(); |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
public static boolean isIndependent(@NonNull TransitionInfo.Change change, |
| 394 |
@NonNull TransitionInfo info) { |
| 395 |
|
| 396 |
if (change.getParent() == null) return true; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
if (change.getMode() == TRANSIT_CHANGE) return false; |
| 401 |
|
| 402 |
TransitionInfo.Change parentChg = info.getChange(change.getParent()); |
| 403 |
while (parentChg != null) { |
| 404 |
|
| 405 |
|
| 406 |
if (parentChg.getMode() != TRANSIT_CHANGE) return false; |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
if (parentChg.getParent() == null) return true; |
| 411 |
|
| 412 |
parentChg = info.getChange(parentChg.getParent()); |
| 413 |
} |
| 414 |
return false; |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
public void releaseAnimSurfaces() { |
| 422 |
for (int i = mChanges.size() - 1; i >= 0; --i) { |
| 423 |
final Change c = mChanges.get(i); |
| 424 |
if (c.mSnapshot != null) { |
| 425 |
c.mSnapshot.release(); |
| 426 |
c.mSnapshot = null; |
| 427 |
} |
| 428 |
} |
| 429 |
if (mRootLeash != null) { |
| 430 |
mRootLeash.release(); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
public void releaseAllSurfaces() { |
| 440 |
releaseAnimSurfaces(); |
| 441 |
for (int i = mChanges.size() - 1; i >= 0; --i) { |
| 442 |
mChanges.get(i).getLeash().release(); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
public TransitionInfo localRemoteCopy() { |
| 453 |
final TransitionInfo out = new TransitionInfo(mType, mFlags); |
| 454 |
for (int i = 0; i < mChanges.size(); ++i) { |
| 455 |
out.mChanges.add(mChanges.get(i).localRemoteCopy()); |
| 456 |
} |
| 457 |
out.mRootLeash = mRootLeash != null ? new SurfaceControl(mRootLeash, "localRemote") : null; |
| 458 |
|
| 459 |
out.mOptions = mOptions; |
| 460 |
out.mRootOffset.set(mRootOffset); |
| 461 |
return out; |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
public static final class Change implements Parcelable { |
| 466 |
private final WindowContainerToken mContainer; |
| 467 |
private WindowContainerToken mParent; |
| 468 |
private WindowContainerToken mLastParent; |
| 469 |
private final SurfaceControl mLeash; |
| 470 |
private @TransitionMode int mMode = TRANSIT_NONE; |
| 471 |
private @ChangeFlags int mFlags = FLAG_NONE; |
| 472 |
private final Rect mStartAbsBounds = new Rect(); |
| 473 |
private final Rect mEndAbsBounds = new Rect(); |
| 474 |
private final Point mEndRelOffset = new Point(); |
| 475 |
private ActivityManager.RunningTaskInfo mTaskInfo = null; |
| 476 |
private boolean mAllowEnterPip; |
| 477 |
private @Surface.Rotation int mStartRotation = ROTATION_UNDEFINED; |
| 478 |
private @Surface.Rotation int mEndRotation = ROTATION_UNDEFINED; |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
private @Surface.Rotation int mEndFixedRotation = ROTATION_UNDEFINED; |
| 484 |
private int mRotationAnimation = ROTATION_ANIMATION_UNSPECIFIED; |
| 485 |
private @ColorInt int mBackgroundColor; |
| 486 |
private SurfaceControl mSnapshot = null; |
| 487 |
private float mSnapshotLuma; |
| 488 |
|
| 489 |
public Change(@Nullable WindowContainerToken container, @NonNull SurfaceControl leash) { |
| 490 |
mContainer = container; |
| 491 |
mLeash = leash; |
| 492 |
} |
| 493 |
|
| 494 |
private Change(Parcel in) { |
| 495 |
mContainer = in.readTypedObject(WindowContainerToken.CREATOR); |
| 496 |
mParent = in.readTypedObject(WindowContainerToken.CREATOR); |
| 497 |
mLastParent = in.readTypedObject(WindowContainerToken.CREATOR); |
| 498 |
mLeash = new SurfaceControl(); |
| 499 |
mLeash.readFromParcel(in); |
| 500 |
mMode = in.readInt(); |
| 501 |
mFlags = in.readInt(); |
| 502 |
mStartAbsBounds.readFromParcel(in); |
| 503 |
mEndAbsBounds.readFromParcel(in); |
| 504 |
mEndRelOffset.readFromParcel(in); |
| 505 |
mTaskInfo = in.readTypedObject(ActivityManager.RunningTaskInfo.CREATOR); |
| 506 |
mAllowEnterPip = in.readBoolean(); |
| 507 |
mStartRotation = in.readInt(); |
| 508 |
mEndRotation = in.readInt(); |
| 509 |
mEndFixedRotation = in.readInt(); |
| 510 |
mRotationAnimation = in.readInt(); |
| 511 |
mBackgroundColor = in.readInt(); |
| 512 |
mSnapshot = in.readTypedObject(SurfaceControl.CREATOR); |
| 513 |
mSnapshotLuma = in.readFloat(); |
| 514 |
} |
| 515 |
|
| 516 |
private Change localRemoteCopy() { |
| 517 |
final Change out = new Change(mContainer, new SurfaceControl(mLeash, "localRemote")); |
| 518 |
out.mParent = mParent; |
| 519 |
out.mLastParent = mLastParent; |
| 520 |
out.mMode = mMode; |
| 521 |
out.mFlags = mFlags; |
| 522 |
out.mStartAbsBounds.set(mStartAbsBounds); |
| 523 |
out.mEndAbsBounds.set(mEndAbsBounds); |
| 524 |
out.mEndRelOffset.set(mEndRelOffset); |
| 525 |
out.mTaskInfo = mTaskInfo; |
| 526 |
out.mAllowEnterPip = mAllowEnterPip; |
| 527 |
out.mStartRotation = mStartRotation; |
| 528 |
out.mEndRotation = mEndRotation; |
| 529 |
out.mEndFixedRotation = mEndFixedRotation; |
| 530 |
out.mRotationAnimation = mRotationAnimation; |
| 531 |
out.mBackgroundColor = mBackgroundColor; |
| 532 |
out.mSnapshot = mSnapshot != null ? new SurfaceControl(mSnapshot, "localRemote") : null; |
| 533 |
out.mSnapshotLuma = mSnapshotLuma; |
| 534 |
return out; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
public void setParent(@Nullable WindowContainerToken parent) { |
| 539 |
mParent = parent; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public void setLastParent(@Nullable WindowContainerToken lastParent) { |
| 547 |
mLastParent = lastParent; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
public void setMode(@TransitionMode int mode) { |
| 552 |
mMode = mode; |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
public void setFlags(@ChangeFlags int flags) { |
| 557 |
mFlags = flags; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
public void setStartAbsBounds(@Nullable Rect rect) { |
| 562 |
mStartAbsBounds.set(rect); |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
public void setEndAbsBounds(@Nullable Rect rect) { |
| 567 |
mEndAbsBounds.set(rect); |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
public void setEndRelOffset(int left, int top) { |
| 572 |
mEndRelOffset.set(left, top); |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
public void setTaskInfo(@Nullable ActivityManager.RunningTaskInfo taskInfo) { |
| 580 |
mTaskInfo = taskInfo; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
public void setAllowEnterPip(boolean allowEnterPip) { |
| 585 |
mAllowEnterPip = allowEnterPip; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
public void setRotation(@Surface.Rotation int start, @Surface.Rotation int end) { |
| 590 |
mStartRotation = start; |
| 591 |
mEndRotation = end; |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
public void setEndFixedRotation(@Surface.Rotation int endFixedRotation) { |
| 596 |
mEndFixedRotation = endFixedRotation; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
public void setRotationAnimation(int anim) { |
| 604 |
mRotationAnimation = anim; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
public void setBackgroundColor(@ColorInt int backgroundColor) { |
| 609 |
mBackgroundColor = backgroundColor; |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
public void setSnapshot(@Nullable SurfaceControl snapshot, float luma) { |
| 614 |
mSnapshot = snapshot; |
| 615 |
mSnapshotLuma = luma; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
@Nullable |
| 620 |
public WindowContainerToken getContainer() { |
| 621 |
return mContainer; |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
@Nullable |
| 629 |
public WindowContainerToken getParent() { |
| 630 |
return mParent; |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
@Nullable |
| 640 |
public WindowContainerToken getLastParent() { |
| 641 |
return mLastParent; |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
public @TransitionMode int getMode() { |
| 646 |
return mMode; |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
public @ChangeFlags int getFlags() { |
| 651 |
return mFlags; |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
public boolean hasFlags(@ChangeFlags int flags) { |
| 656 |
return (mFlags & flags) != 0; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
public boolean hasAllFlags(@ChangeFlags int flags) { |
| 661 |
return (mFlags & flags) == flags; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
@NonNull |
| 669 |
public Rect getStartAbsBounds() { |
| 670 |
return mStartAbsBounds; |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
@NonNull |
| 678 |
public Rect getEndAbsBounds() { |
| 679 |
return mEndAbsBounds; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
@NonNull |
| 686 |
public Point getEndRelOffset() { |
| 687 |
return mEndRelOffset; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
@NonNull |
| 692 |
public SurfaceControl getLeash() { |
| 693 |
return mLeash; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
@Nullable |
| 698 |
public ActivityManager.RunningTaskInfo getTaskInfo() { |
| 699 |
return mTaskInfo; |
| 700 |
} |
| 701 |
|
| 702 |
public boolean getAllowEnterPip() { |
| 703 |
return mAllowEnterPip; |
| 704 |
} |
| 705 |
|
| 706 |
@Surface.Rotation |
| 707 |
public int getStartRotation() { |
| 708 |
return mStartRotation; |
| 709 |
} |
| 710 |
|
| 711 |
@Surface.Rotation |
| 712 |
public int getEndRotation() { |
| 713 |
return mEndRotation; |
| 714 |
} |
| 715 |
|
| 716 |
@Surface.Rotation |
| 717 |
public int getEndFixedRotation() { |
| 718 |
return mEndFixedRotation; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
public int getRotationAnimation() { |
| 723 |
return mRotationAnimation; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
@ColorInt |
| 728 |
public int getBackgroundColor() { |
| 729 |
return mBackgroundColor; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
@Nullable |
| 734 |
public SurfaceControl getSnapshot() { |
| 735 |
return mSnapshot; |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
public float getSnapshotLuma() { |
| 740 |
return mSnapshotLuma; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
@Override |
| 745 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 746 |
dest.writeTypedObject(mContainer, flags); |
| 747 |
dest.writeTypedObject(mParent, flags); |
| 748 |
dest.writeTypedObject(mLastParent, flags); |
| 749 |
mLeash.writeToParcel(dest, flags); |
| 750 |
dest.writeInt(mMode); |
| 751 |
dest.writeInt(mFlags); |
| 752 |
mStartAbsBounds.writeToParcel(dest, flags); |
| 753 |
mEndAbsBounds.writeToParcel(dest, flags); |
| 754 |
mEndRelOffset.writeToParcel(dest, flags); |
| 755 |
dest.writeTypedObject(mTaskInfo, flags); |
| 756 |
dest.writeBoolean(mAllowEnterPip); |
| 757 |
dest.writeInt(mStartRotation); |
| 758 |
dest.writeInt(mEndRotation); |
| 759 |
dest.writeInt(mEndFixedRotation); |
| 760 |
dest.writeInt(mRotationAnimation); |
| 761 |
dest.writeInt(mBackgroundColor); |
| 762 |
dest.writeTypedObject(mSnapshot, flags); |
| 763 |
dest.writeFloat(mSnapshotLuma); |
| 764 |
} |
| 765 |
|
| 766 |
@NonNull |
| 767 |
public static final Creator<Change> CREATOR = |
| 768 |
new Creator<Change>() { |
| 769 |
@Override |
| 770 |
public Change createFromParcel(Parcel in) { |
| 771 |
return new Change(in); |
| 772 |
} |
| 773 |
|
| 774 |
@Override |
| 775 |
public Change[] newArray(int size) { |
| 776 |
return new Change[size]; |
| 777 |
} |
| 778 |
}; |
| 779 |
|
| 780 |
|
| 781 |
@Override |
| 782 |
public int describeContents() { |
| 783 |
return 0; |
| 784 |
} |
| 785 |
|
| 786 |
@Override |
| 787 |
public String toString() { |
| 788 |
final StringBuilder sb = new StringBuilder(); |
| 789 |
sb.append('{'); sb.append(mContainer); |
| 790 |
sb.append(" m="); sb.append(modeToString(mMode)); |
| 791 |
sb.append(" f="); sb.append(flagsToString(mFlags)); |
| 792 |
if (mParent != null) { |
| 793 |
sb.append(" p="); sb.append(mParent); |
| 794 |
} |
| 795 |
if (mLeash != null) { |
| 796 |
sb.append(" leash="); sb.append(mLeash); |
| 797 |
} |
| 798 |
sb.append(" sb="); sb.append(mStartAbsBounds); |
| 799 |
sb.append(" eb="); sb.append(mEndAbsBounds); |
| 800 |
if (mEndRelOffset.x != 0 || mEndRelOffset.y != 0) { |
| 801 |
sb.append(" eo="); sb.append(mEndRelOffset); |
| 802 |
} |
| 803 |
if (mStartRotation != mEndRotation) { |
| 804 |
sb.append(" r="); sb.append(mStartRotation); |
| 805 |
sb.append("->"); sb.append(mEndRotation); |
| 806 |
sb.append(':'); sb.append(mRotationAnimation); |
| 807 |
} |
| 808 |
if (mEndFixedRotation != ROTATION_UNDEFINED) { |
| 809 |
sb.append(" endFixedRotation="); sb.append(mEndFixedRotation); |
| 810 |
} |
| 811 |
if (mSnapshot != null) { |
| 812 |
sb.append(" snapshot="); sb.append(mSnapshot); |
| 813 |
} |
| 814 |
if (mLastParent != null) { |
| 815 |
sb.append(" lastParent="); sb.append(mLastParent); |
| 816 |
} |
| 817 |
sb.append('}'); |
| 818 |
return sb.toString(); |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
public static final class AnimationOptions implements Parcelable { |
| 824 |
|
| 825 |
private int mType; |
| 826 |
private int mEnterResId; |
| 827 |
private int mExitResId; |
| 828 |
private boolean mOverrideTaskTransition; |
| 829 |
private String mPackageName; |
| 830 |
private final Rect mTransitionBounds = new Rect(); |
| 831 |
private HardwareBuffer mThumbnail; |
| 832 |
private int mAnimations; |
| 833 |
private @ColorInt int mBackgroundColor; |
| 834 |
|
| 835 |
private AnimationOptions(int type) { |
| 836 |
mType = type; |
| 837 |
} |
| 838 |
|
| 839 |
public AnimationOptions(Parcel in) { |
| 840 |
mType = in.readInt(); |
| 841 |
mEnterResId = in.readInt(); |
| 842 |
mExitResId = in.readInt(); |
| 843 |
mBackgroundColor = in.readInt(); |
| 844 |
mOverrideTaskTransition = in.readBoolean(); |
| 845 |
mPackageName = in.readString(); |
| 846 |
mTransitionBounds.readFromParcel(in); |
| 847 |
mThumbnail = in.readTypedObject(HardwareBuffer.CREATOR); |
| 848 |
mAnimations = in.readInt(); |
| 849 |
} |
| 850 |
|
| 851 |
public static AnimationOptions makeAnimOptionsFromLayoutParameters( |
| 852 |
WindowManager.LayoutParams lp) { |
| 853 |
AnimationOptions options = new AnimationOptions(ANIM_FROM_STYLE); |
| 854 |
options.mPackageName = lp.packageName; |
| 855 |
options.mAnimations = lp.windowAnimations; |
| 856 |
return options; |
| 857 |
} |
| 858 |
|
| 859 |
public static AnimationOptions makeCustomAnimOptions(String packageName, int enterResId, |
| 860 |
int exitResId, @ColorInt int backgroundColor, boolean overrideTaskTransition) { |
| 861 |
AnimationOptions options = new AnimationOptions(ANIM_CUSTOM); |
| 862 |
options.mPackageName = packageName; |
| 863 |
options.mEnterResId = enterResId; |
| 864 |
options.mExitResId = exitResId; |
| 865 |
options.mBackgroundColor = backgroundColor; |
| 866 |
options.mOverrideTaskTransition = overrideTaskTransition; |
| 867 |
return options; |
| 868 |
} |
| 869 |
|
| 870 |
public static AnimationOptions makeClipRevealAnimOptions(int startX, int startY, int width, |
| 871 |
int height) { |
| 872 |
AnimationOptions options = new AnimationOptions(ANIM_CLIP_REVEAL); |
| 873 |
options.mTransitionBounds.set(startX, startY, startX + width, startY + height); |
| 874 |
return options; |
| 875 |
} |
| 876 |
|
| 877 |
public static AnimationOptions makeScaleUpAnimOptions(int startX, int startY, int width, |
| 878 |
int height) { |
| 879 |
AnimationOptions options = new AnimationOptions(ANIM_SCALE_UP); |
| 880 |
options.mTransitionBounds.set(startX, startY, startX + width, startY + height); |
| 881 |
return options; |
| 882 |
} |
| 883 |
|
| 884 |
public static AnimationOptions makeThumbnailAnimOptions(HardwareBuffer srcThumb, |
| 885 |
int startX, int startY, boolean scaleUp) { |
| 886 |
AnimationOptions options = new AnimationOptions( |
| 887 |
scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN); |
| 888 |
options.mTransitionBounds.set(startX, startY, startX, startY); |
| 889 |
options.mThumbnail = srcThumb; |
| 890 |
return options; |
| 891 |
} |
| 892 |
|
| 893 |
public static AnimationOptions makeCrossProfileAnimOptions() { |
| 894 |
AnimationOptions options = new AnimationOptions(ANIM_OPEN_CROSS_PROFILE_APPS); |
| 895 |
return options; |
| 896 |
} |
| 897 |
|
| 898 |
public int getType() { |
| 899 |
return mType; |
| 900 |
} |
| 901 |
|
| 902 |
public int getEnterResId() { |
| 903 |
return mEnterResId; |
| 904 |
} |
| 905 |
|
| 906 |
public int getExitResId() { |
| 907 |
return mExitResId; |
| 908 |
} |
| 909 |
|
| 910 |
public @ColorInt int getBackgroundColor() { |
| 911 |
return mBackgroundColor; |
| 912 |
} |
| 913 |
|
| 914 |
public boolean getOverrideTaskTransition() { |
| 915 |
return mOverrideTaskTransition; |
| 916 |
} |
| 917 |
|
| 918 |
public String getPackageName() { |
| 919 |
return mPackageName; |
| 920 |
} |
| 921 |
|
| 922 |
public Rect getTransitionBounds() { |
| 923 |
return mTransitionBounds; |
| 924 |
} |
| 925 |
|
| 926 |
public HardwareBuffer getThumbnail() { |
| 927 |
return mThumbnail; |
| 928 |
} |
| 929 |
|
| 930 |
public int getAnimations() { |
| 931 |
return mAnimations; |
| 932 |
} |
| 933 |
|
| 934 |
@Override |
| 935 |
public void writeToParcel(Parcel dest, int flags) { |
| 936 |
dest.writeInt(mType); |
| 937 |
dest.writeInt(mEnterResId); |
| 938 |
dest.writeInt(mExitResId); |
| 939 |
dest.writeInt(mBackgroundColor); |
| 940 |
dest.writeBoolean(mOverrideTaskTransition); |
| 941 |
dest.writeString(mPackageName); |
| 942 |
mTransitionBounds.writeToParcel(dest, flags); |
| 943 |
dest.writeTypedObject(mThumbnail, flags); |
| 944 |
dest.writeInt(mAnimations); |
| 945 |
} |
| 946 |
|
| 947 |
@NonNull |
| 948 |
public static final Creator<AnimationOptions> CREATOR = |
| 949 |
new Creator<AnimationOptions>() { |
| 950 |
@Override |
| 951 |
public AnimationOptions createFromParcel(Parcel in) { |
| 952 |
return new AnimationOptions(in); |
| 953 |
} |
| 954 |
|
| 955 |
@Override |
| 956 |
public AnimationOptions[] newArray(int size) { |
| 957 |
return new AnimationOptions[size]; |
| 958 |
} |
| 959 |
}; |
| 960 |
|
| 961 |
|
| 962 |
@Override |
| 963 |
public int describeContents() { |
| 964 |
return 0; |
| 965 |
} |
| 966 |
|
| 967 |
@NonNull |
| 968 |
private static String typeToString(int mode) { |
| 969 |
switch(mode) { |
| 970 |
case ANIM_CUSTOM: return "ANIM_CUSTOM"; |
| 971 |
case ANIM_CLIP_REVEAL: return "ANIM_CLIP_REVEAL"; |
| 972 |
case ANIM_SCALE_UP: return "ANIM_SCALE_UP"; |
| 973 |
case ANIM_THUMBNAIL_SCALE_UP: return "ANIM_THUMBNAIL_SCALE_UP"; |
| 974 |
case ANIM_THUMBNAIL_SCALE_DOWN: return "ANIM_THUMBNAIL_SCALE_DOWN"; |
| 975 |
case ANIM_OPEN_CROSS_PROFILE_APPS: return "ANIM_OPEN_CROSS_PROFILE_APPS"; |
| 976 |
default: return "<unknown:" + mode + ">"; |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
@Override |
| 981 |
public String toString() { |
| 982 |
return "{ AnimationOptions type= " + typeToString(mType) + " package=" + mPackageName |
| 983 |
+ " override=" + mOverrideTaskTransition + " b=" + mTransitionBounds + "}"; |
| 984 |
} |
| 985 |
} |
| 986 |
} |