1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
|
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.window;
import static android.app.ActivityOptions.ANIM_CLIP_REVEAL;
import static android.app.ActivityOptions.ANIM_CUSTOM;
import static android.app.ActivityOptions.ANIM_FROM_STYLE;
import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS;
import static android.app.ActivityOptions.ANIM_SCALE_UP;
import static android.app.ActivityOptions.ANIM_SCENE_TRANSITION;
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN;
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_AOD_APPEARING;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_APPEARING;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY;
import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.view.WindowManager.TransitionFlags;
import static android.view.WindowManager.TransitionType;
import static android.view.WindowManager.transitTypeToString;
import android.annotation.AnimRes;
import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.BinderProxy;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.WindowManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Used to communicate information about what is changing during a transition to a TransitionPlayer.
* @hide
*/
public final class TransitionInfo implements Parcelable {
private static final String TAG = "TransitionInfo";
/**
* Modes are only a sub-set of all the transit-types since they are per-container
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "TRANSIT_" }, value = {
TRANSIT_NONE,
TRANSIT_OPEN,
TRANSIT_CLOSE,
// Note: to_front/to_back really mean show/hide respectively at the container level.
TRANSIT_TO_FRONT,
TRANSIT_TO_BACK,
TRANSIT_CHANGE
})
public @interface TransitionMode {}
/** No flags */
public static final int FLAG_NONE = 0;
/** The container shows the wallpaper behind it. */
public static final int FLAG_SHOW_WALLPAPER = 1;
/** The container IS the wallpaper. */
public static final int FLAG_IS_WALLPAPER = 1 << 1;
/** The container is translucent. */
public static final int FLAG_TRANSLUCENT = 1 << 2;
// TODO: remove when starting-window is moved to Task
/** The container is the recipient of a transferred starting-window */
public static final int FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT = 1 << 3;
/** The container has voice session. */
public static final int FLAG_IS_VOICE_INTERACTION = 1 << 4;
/** The container is the display. */
public static final int FLAG_IS_DISPLAY = 1 << 5;
// TODO(b/194540864): Once we can include all windows in transition, then replace this with
// something like FLAG_IS_SYSTEM_ALERT instead. Then we can do mixed rotations.
/**
* Only for IS_DISPLAY containers. Is set if the display has system alert windows. This is
* used to prevent seamless rotation.
*/
public static final int FLAG_DISPLAY_HAS_ALERT_WINDOWS = 1 << 7;
/** The container is an input-method window. */
public static final int FLAG_IS_INPUT_METHOD = 1 << 8;
/** The container is in a Task with embedded activity. */
public static final int FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY = 1 << 9;
/** The container fills its parent Task before and after the transition. */
public static final int FLAG_FILLS_TASK = 1 << 10;
/** The container is going to show IME on its task after the transition. */
public static final int FLAG_WILL_IME_SHOWN = 1 << 11;
/** The container attaches owner profile thumbnail for cross profile animation. */
public static final int FLAG_CROSS_PROFILE_OWNER_THUMBNAIL = 1 << 12;
/** The container attaches work profile thumbnail for cross profile animation. */
public static final int FLAG_CROSS_PROFILE_WORK_THUMBNAIL = 1 << 13;
/**
* Whether the window is covered by an app starting window. This is different from
* {@link #FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT} which is only set on the Activity window
* that contains the starting window.
*/
public static final int FLAG_IS_BEHIND_STARTING_WINDOW = 1 << 14;
/** This change happened underneath something else. */
public static final int FLAG_IS_OCCLUDED = 1 << 15;
/** The container is a system window, excluding wallpaper and input-method. */
public static final int FLAG_IS_SYSTEM_WINDOW = 1 << 16;
/** The window was animated by back gesture. */
public static final int FLAG_BACK_GESTURE_ANIMATED = 1 << 17;
/** The window should have no animation (by policy). */
public static final int FLAG_NO_ANIMATION = 1 << 18;
/** The task is launching behind home. */
public static final int FLAG_TASK_LAUNCHING_BEHIND = 1 << 19;
/** The task became the top-most task even if it didn't change visibility. */
public static final int FLAG_MOVED_TO_TOP = 1 << 20;
/**
* This transition must be the only transition when it starts (ie. it must wait for all other
* transition animations to finish).
*/
public static final int FLAG_SYNC = 1 << 21;
/** This change represents its start configuration for the duration of the animation. */
public static final int FLAG_CONFIG_AT_END = 1 << 22;
/** This change represents one of a Task Display Area. */
public static final int FLAG_IS_TASK_DISPLAY_AREA = 1 << 23;
/** The first unused bit. This can be used by remotes to attach custom flags to this change. */
public static final int FLAG_FIRST_CUSTOM = 1 << 24;
/** The change belongs to a window that won't contain activities. */
public static final int FLAGS_IS_NON_APP_WINDOW =
FLAG_IS_WALLPAPER | FLAG_IS_INPUT_METHOD | FLAG_IS_SYSTEM_WINDOW;
/** The change will not participate in the animation. */
public static final int FLAGS_IS_OCCLUDED_NO_ANIMATION = FLAG_IS_OCCLUDED | FLAG_NO_ANIMATION;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "FLAG_" }, flag = true, value = {
FLAG_NONE,
FLAG_SHOW_WALLPAPER,
FLAG_IS_WALLPAPER,
FLAG_TRANSLUCENT,
FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT,
FLAG_IS_VOICE_INTERACTION,
FLAG_IS_DISPLAY,
FLAG_DISPLAY_HAS_ALERT_WINDOWS,
FLAG_IS_INPUT_METHOD,
FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY,
FLAG_FILLS_TASK,
FLAG_WILL_IME_SHOWN,
FLAG_CROSS_PROFILE_OWNER_THUMBNAIL,
FLAG_CROSS_PROFILE_WORK_THUMBNAIL,
FLAG_IS_BEHIND_STARTING_WINDOW,
FLAG_IS_OCCLUDED,
FLAG_IS_SYSTEM_WINDOW,
FLAG_BACK_GESTURE_ANIMATED,
FLAG_NO_ANIMATION,
FLAG_TASK_LAUNCHING_BEHIND,
FLAG_MOVED_TO_TOP,
FLAG_SYNC,
FLAG_CONFIG_AT_END,
FLAG_IS_TASK_DISPLAY_AREA,
FLAG_FIRST_CUSTOM
})
public @interface ChangeFlags {}
private final @TransitionType int mType;
private @TransitionFlags int mFlags;
private int mTrack = 0;
private final ArrayList<Change> mChanges = new ArrayList<>();
private final ArrayList<Root> mRoots = new ArrayList<>();
/** This is only a BEST-EFFORT id used for log correlation. DO NOT USE for any real work! */
private int mDebugId = -1;
/** @hide */
public TransitionInfo(@TransitionType int type, @TransitionFlags int flags) {
mType = type;
mFlags = flags;
}
private TransitionInfo(Parcel in) {
mType = in.readInt();
mFlags = in.readInt();
in.readTypedList(mChanges, Change.CREATOR);
in.readTypedList(mRoots, Root.CREATOR);
mDebugId = in.readInt();
mTrack = in.readInt();
}
@Override
/** @hide */
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mType);
dest.writeInt(mFlags);
dest.writeTypedList(mChanges);
dest.writeTypedList(mRoots, flags);
dest.writeInt(mDebugId);
dest.writeInt(mTrack);
}
@NonNull
public static final Creator<TransitionInfo> CREATOR =
new Creator<TransitionInfo>() {
@Override
public TransitionInfo createFromParcel(Parcel in) {
return new TransitionInfo(in);
}
@Override
public TransitionInfo[] newArray(int size) {
return new TransitionInfo[size];
}
};
@Override
/** @hide */
public int describeContents() {
return 0;
}
/** @see #getRoot */
public void addRootLeash(int displayId, @NonNull SurfaceControl leash,
int offsetLeft, int offsetTop) {
mRoots.add(new Root(displayId, leash, offsetLeft, offsetTop));
}
/** @see #getRoot */
public void addRoot(@NonNull Root other) {
mRoots.add(other);
}
public @TransitionType int getType() {
return mType;
}
public void setFlags(int flags) {
mFlags = flags;
}
public int getFlags() {
return mFlags;
}
/**
* @return The number of animation roots. Most transitions should have 1, but there may be more
* in some cases (such as a transition spanning multiple displays).
*/
public int getRootCount() {
return mRoots.size();
}
/**
* @return the transition-root at a specific index.
*/
@NonNull
public Root getRoot(int idx) {
return mRoots.get(idx);
}
/**
* @return the index of the transition-root associated with `displayId` or -1 if not found.
*/
public int findRootIndex(int displayId) {
for (int i = 0; i < mRoots.size(); ++i) {
if (mRoots.get(i).mDisplayId == displayId) {
return i;
}
}
return -1;
}
/**
* @return a surfacecontrol that can serve as a parent surfacecontrol for all the changing
* participants to animate within. This will generally be placed at the highest-z-order
* shared ancestor of all participants. While this is non-null, it's possible for the rootleash
* to be invalid if the transition is a no-op.
*
* @deprecated Use {@link #getRoot} instead. This call assumes there is only one root.
*/
@Deprecated
@NonNull
public SurfaceControl getRootLeash() {
if (mRoots.isEmpty()) {
throw new IllegalStateException("Trying to get a root leash from a no-op transition.");
}
if (mRoots.size() > 1) {
android.util.Log.e(TAG, "Assuming one animation root when there are more.",
new Throwable());
}
return mRoots.get(0).mLeash;
}
/**
* @return the list of {@link Change}s in this transition. The list is sorted top-to-bottom
* in Z (meaning index 0 is the top-most container).
*/
@NonNull
public List<Change> getChanges() {
return mChanges;
}
/**
* @return the Change that a window is undergoing or {@code null} if not directly
* represented.
*/
@Nullable
public Change getChange(@NonNull WindowContainerToken token) {
for (int i = mChanges.size() - 1; i >= 0; --i) {
if (token.equals(mChanges.get(i).mContainer)) {
return mChanges.get(i);
}
}
return null;
}
/**
* Add a {@link Change} to this transition.
*/
public void addChange(@NonNull Change change) {
mChanges.add(change);
}
/**
* Whether this transition contains any changes to the window hierarchy,
* including keyguard visibility.
*/
public boolean hasChangesOrSideEffects() {
return !mChanges.isEmpty() || isKeyguardGoingAway()
|| (mFlags & TRANSIT_FLAG_KEYGUARD_APPEARING) != 0
|| (mFlags & TRANSIT_FLAG_AOD_APPEARING) != 0;
}
/**
* Whether this transition includes keyguard going away.
*/
public boolean isKeyguardGoingAway() {
return (mFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY) != 0;
}
/** Gets which animation track this transition should run on. */
public int getTrack() {
return mTrack;
}
/** Sets which animation track this transition should run on. */
public void setTrack(int track) {
mTrack = track;
}
/**
* Set an arbitrary "debug" id for this info. This id will not be used for any "real work",
* it is just for debugging and logging.
*/
public void setDebugId(int id) {
mDebugId = id;
}
/** Get the "debug" id of this info. Do NOT use this for real work, only use for debugging. */
public int getDebugId() {
return mDebugId;
}
@Override
public String toString() {
return toString("");
}
/**
* Returns a string representation of this transition info.
* @hide
*/
public String toString(@NonNull String prefix) {
final boolean shouldPrettyPrint = !prefix.isEmpty() && !mChanges.isEmpty();
final String innerPrefix = shouldPrettyPrint ? prefix + " " : "";
final String changesLineStart = shouldPrettyPrint ? "\n" + prefix : "";
final String perChangeLineStart = shouldPrettyPrint ? "\n" + innerPrefix : "";
StringBuilder sb = new StringBuilder();
sb.append("{id=").append(mDebugId).append(" t=").append(transitTypeToString(mType))
.append(" f=0x").append(Integer.toHexString(mFlags)).append(" trk=").append(mTrack);
sb.append(" r=[");
for (int i = 0; i < mRoots.size(); ++i) {
if (i > 0) {
sb.append(',');
}
sb.append(mRoots.get(i).mDisplayId).append("@").append(mRoots.get(i).mOffset);
}
sb.append("] c=[");
sb.append(perChangeLineStart);
for (int i = 0; i < mChanges.size(); ++i) {
if (i > 0) {
sb.append(',');
sb.append(perChangeLineStart);
}
sb.append(mChanges.get(i));
}
sb.append(changesLineStart);
sb.append("]}");
return sb.toString();
}
/** Converts a transition mode/action to its string representation. */
@NonNull
public static String modeToString(@TransitionMode int mode) {
switch(mode) {
case TRANSIT_NONE: return "NONE";
case TRANSIT_OPEN: return "OPEN";
case TRANSIT_CLOSE: return "CLOSE";
case TRANSIT_TO_FRONT: return "TO_FRONT";
case TRANSIT_TO_BACK: return "TO_BACK";
case TRANSIT_CHANGE: return "CHANGE";
default: return "<unknown:" + mode + ">";
}
}
/** Converts change flags into a string representation. */
@NonNull
public static String flagsToString(@ChangeFlags int flags) {
if (flags == 0) return "NONE";
final StringBuilder sb = new StringBuilder();
if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
sb.append("SHOW_WALLPAPER");
}
if ((flags & FLAG_IS_WALLPAPER) != 0) {
sb.append("IS_WALLPAPER");
}
if ((flags & FLAG_IS_INPUT_METHOD) != 0) {
sb.append("IS_INPUT_METHOD");
}
if ((flags & FLAG_TRANSLUCENT) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("TRANSLUCENT");
}
if ((flags & FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("STARTING_WINDOW_TRANSFER");
}
if ((flags & FLAG_IS_VOICE_INTERACTION) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("IS_VOICE_INTERACTION");
}
if ((flags & FLAG_IS_DISPLAY) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("IS_DISPLAY");
}
if ((flags & FLAG_DISPLAY_HAS_ALERT_WINDOWS) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("DISPLAY_HAS_ALERT_WINDOWS");
}
if ((flags & FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("IN_TASK_WITH_EMBEDDED_ACTIVITY");
}
if ((flags & FLAG_FILLS_TASK) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("FILLS_TASK");
}
if ((flags & FLAG_IS_BEHIND_STARTING_WINDOW) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("IS_BEHIND_STARTING_WINDOW");
}
if ((flags & FLAG_IS_OCCLUDED) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("IS_OCCLUDED");
}
if ((flags & FLAG_IS_SYSTEM_WINDOW) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("FLAG_IS_SYSTEM_WINDOW");
}
if ((flags & FLAG_BACK_GESTURE_ANIMATED) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("FLAG_BACK_GESTURE_ANIMATED");
}
if ((flags & FLAG_NO_ANIMATION) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("NO_ANIMATION");
}
if ((flags & FLAG_TASK_LAUNCHING_BEHIND) != 0) {
sb.append((sb.length() == 0 ? "" : "|") + "TASK_LAUNCHING_BEHIND");
}
if ((flags & FLAG_SYNC) != 0) {
sb.append((sb.length() == 0 ? "" : "|") + "SYNC");
}
if ((flags & FLAG_FIRST_CUSTOM) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("FIRST_CUSTOM");
}
if ((flags & FLAG_CONFIG_AT_END) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("CONFIG_AT_END");
}
if ((flags & FLAG_MOVED_TO_TOP) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("MOVE_TO_TOP");
}
if ((flags & FLAG_IS_TASK_DISPLAY_AREA) != 0) {
sb.append(sb.length() == 0 ? "" : "|").append("FLAG_IS_TASK_DISPLAY_AREA");
}
return sb.toString();
}
/**
* Indication that `change` is independent of parents (ie. it has a different type of
* transition vs. "going along for the ride")
*/
public static boolean isIndependent(@NonNull TransitionInfo.Change change,
@NonNull TransitionInfo info) {
// If the change has no parent (it is root), then it is independent
if (change.getParent() == null) return true;
if (change.getLastParent() != null && !change.getLastParent().equals(change.getParent())) {
// If the change has been reparented, then it's independent.
return true;
}
// non-visibility changes will just be folded into the parent change, so they aren't
// independent either.
if (change.getMode() == TRANSIT_CHANGE) return false;
// Always fold the activity embedding change into the parent change.
if (change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY)) return false;
TransitionInfo.Change parentChg = info.getChange(change.getParent());
while (parentChg != null) {
// If the parent is a visibility change, it will include the results of all child
// changes into itself, so none of its children can be independent.
if (parentChg.getMode() != TRANSIT_CHANGE) return false;
// If there are no more parents left, then all the parents, so far, have not been
// visibility changes which means this change is independent.
if (parentChg.getParent() == null) return true;
parentChg = info.getChange(parentChg.getParent());
}
return false;
}
/**
* Releases temporary-for-animation surfaces referenced by this to potentially free up memory.
* This includes root-leash and snapshots.
*/
public void releaseAnimSurfaces() {
for (int i = mChanges.size() - 1; i >= 0; --i) {
final Change c = mChanges.get(i);
if (c.mSnapshot != null) {
c.mSnapshot.release();
c.mSnapshot = null;
}
}
for (int i = 0; i < mRoots.size(); ++i) {
mRoots.get(i).mLeash.release();
}
}
/**
* Releases ALL the surfaces referenced by this to potentially free up memory. Do NOT use this
* if the surface-controls get stored and used elsewhere in the process. To just release
* temporary-for-animation surfaces, use {@link #releaseAnimSurfaces}.
*/
public void releaseAllSurfaces() {
releaseAnimSurfaces();
for (int i = mChanges.size() - 1; i >= 0; --i) {
mChanges.get(i).getLeash().release();
}
}
/**
* Updates the callsites of all the surfaces in this transition, which aids in the debugging of
* lingering surfaces.
*/
public void setUnreleasedWarningCallSiteForAllSurfaces(@Nullable String callsite) {
for (int i = mChanges.size() - 1; i >= 0; --i) {
mChanges.get(i).getLeash().setUnreleasedWarningCallSite(callsite);
}
}
/**
* Makes a copy of this as if it were parcel'd and unparcel'd. This implies that surfacecontrol
* refcounts are incremented which allows the "remote" receiver to release them without breaking
* the caller's references. Use this only if you need to "send" this to a local function which
* assumes it is being called from a remote caller.
*/
@NonNull
public TransitionInfo localRemoteCopy() {
final TransitionInfo out = new TransitionInfo(mType, mFlags);
out.mTrack = mTrack;
out.mDebugId = mDebugId;
for (int i = 0; i < mChanges.size(); ++i) {
out.mChanges.add(mChanges.get(i).localRemoteCopy());
}
for (int i = 0; i < mRoots.size(); ++i) {
out.mRoots.add(mRoots.get(i).localRemoteCopy());
}
return out;
}
/** Represents the change a WindowContainer undergoes during a transition */
public static final class Change implements Parcelable {
private final WindowContainerToken mContainer;
private WindowContainerToken mParent;
private WindowContainerToken mLastParent;
private SurfaceControl mLeash;
private @TransitionMode int mMode = TRANSIT_NONE;
private @ChangeFlags int mFlags = FLAG_NONE;
private final Rect mStartAbsBounds = new Rect();
private final Rect mEndAbsBounds = new Rect();
private final Point mEndRelOffset = new Point();
private final Point mEndParentSize = new Point();
private ActivityManager.RunningTaskInfo mTaskInfo = null;
private boolean mAllowEnterPip;
private int mStartDisplayId = INVALID_DISPLAY;
private int mEndDisplayId = INVALID_DISPLAY;
private @Surface.Rotation int mStartRotation = ROTATION_UNDEFINED;
private @Surface.Rotation int mEndRotation = ROTATION_UNDEFINED;
/**
* The end rotation of the top activity after fixed rotation is finished. If the top
* activity is not in fixed rotation, it will be {@link ROTATION_UNDEFINED}.
*/
private @Surface.Rotation int mEndFixedRotation = ROTATION_UNDEFINED;
private int mRotationAnimation = ROTATION_ANIMATION_UNSPECIFIED;
private @ColorInt int mBackgroundColor;
private SurfaceControl mSnapshot = null;
private float mSnapshotLuma;
private ActivityTransitionInfo mActivityTransitionInfo = null;
private AnimationOptions mAnimationOptions = null;
private IBinder mTaskFragmentToken = null;
public Change(@Nullable WindowContainerToken container, @NonNull SurfaceControl leash) {
mContainer = container;
mLeash = leash;
}
private Change(@NonNull Parcel in) {
mContainer = in.readTypedObject(WindowContainerToken.CREATOR);
mParent = in.readTypedObject(WindowContainerToken.CREATOR);
mLastParent = in.readTypedObject(WindowContainerToken.CREATOR);
mLeash = new SurfaceControl();
mLeash.readFromParcel(in);
mMode = in.readInt();
mFlags = in.readInt();
mStartAbsBounds.readFromParcel(in);
mEndAbsBounds.readFromParcel(in);
mEndRelOffset.readFromParcel(in);
mEndParentSize.readFromParcel(in);
mTaskInfo = in.readTypedObject(ActivityManager.RunningTaskInfo.CREATOR);
mAllowEnterPip = in.readBoolean();
mStartDisplayId = in.readInt();
mEndDisplayId = in.readInt();
mStartRotation = in.readInt();
mEndRotation = in.readInt();
mEndFixedRotation = in.readInt();
mRotationAnimation = in.readInt();
mBackgroundColor = in.readInt();
mSnapshot = in.readTypedObject(SurfaceControl.CREATOR);
mSnapshotLuma = in.readFloat();
mActivityTransitionInfo = in.readTypedObject(ActivityTransitionInfo.CREATOR);
mAnimationOptions = in.readTypedObject(AnimationOptions.CREATOR);
mTaskFragmentToken = in.readStrongBinder();
}
private Change localRemoteCopy() {
final Change out = new Change(mContainer, new SurfaceControl(mLeash, "localRemote"));
out.mParent = mParent;
out.mLastParent = mLastParent;
out.mMode = mMode;
out.mFlags = mFlags;
out.mStartAbsBounds.set(mStartAbsBounds);
out.mEndAbsBounds.set(mEndAbsBounds);
out.mEndRelOffset.set(mEndRelOffset);
out.mEndParentSize.set(mEndParentSize);
out.mTaskInfo = mTaskInfo;
out.mAllowEnterPip = mAllowEnterPip;
out.mStartDisplayId = mStartDisplayId;
out.mEndDisplayId = mEndDisplayId;
out.mStartRotation = mStartRotation;
out.mEndRotation = mEndRotation;
out.mEndFixedRotation = mEndFixedRotation;
out.mRotationAnimation = mRotationAnimation;
out.mBackgroundColor = mBackgroundColor;
out.mSnapshot = mSnapshot != null ? new SurfaceControl(mSnapshot, "localRemote") : null;
out.mSnapshotLuma = mSnapshotLuma;
if (mActivityTransitionInfo != null) {
out.mActivityTransitionInfo = new ActivityTransitionInfo(mActivityTransitionInfo);
}
out.mAnimationOptions = mAnimationOptions;
out.mTaskFragmentToken = mTaskFragmentToken;
return out;
}
/** Sets the parent of this change's container. The parent must be a participant or null. */
public void setParent(@Nullable WindowContainerToken parent) {
mParent = parent;
}
/**
* Sets the parent of this change's container before the transition if this change's
* container is reparented in the transition.
*/
public void setLastParent(@Nullable WindowContainerToken lastParent) {
mLastParent = lastParent;
}
/** Sets the animation leash for controlling this change's container */
public void setLeash(@NonNull SurfaceControl leash) {
mLeash = Objects.requireNonNull(leash);
}
/** Sets the transition mode for this change */
public void setMode(@TransitionMode int mode) {
mMode = mode;
}
/** Sets the flags for this change */
public void setFlags(@ChangeFlags int flags) {
mFlags = flags;
}
/** Sets the bounds this container occupied before the change in screen space */
public void setStartAbsBounds(@Nullable Rect rect) {
mStartAbsBounds.set(rect);
}
/** Sets the bounds this container will occupy after the change in screen space */
public void setEndAbsBounds(@Nullable Rect rect) {
mEndAbsBounds.set(rect);
}
/** Sets the offset of this container from its parent surface */
public void setEndRelOffset(int left, int top) {
mEndRelOffset.set(left, top);
}
/**
* Sets the size of its parent container after the change.
*/
public void setEndParentSize(int width, int height) {
mEndParentSize.set(width, height);
}
/**
* Sets the taskinfo of this container if this is a task. WARNING: this takes the
* reference, so don't modify it afterwards.
*/
public void setTaskInfo(@Nullable ActivityManager.RunningTaskInfo taskInfo) {
mTaskInfo = taskInfo;
}
/** Sets the allowEnterPip flag which represents AppOpsManager check on PiP permission */
public void setAllowEnterPip(boolean allowEnterPip) {
mAllowEnterPip = allowEnterPip;
}
/** Sets the start and end rotation of this container. */
public void setDisplayId(int start, int end) {
mStartDisplayId = start;
mEndDisplayId = end;
}
/** Sets the start and end rotation of this container. */
public void setRotation(@Surface.Rotation int start, @Surface.Rotation int end) {
mStartRotation = start;
mEndRotation = end;
}
/** Sets end rotation that top activity will be launched to after fixed rotation. */
public void setEndFixedRotation(@Surface.Rotation int endFixedRotation) {
mEndFixedRotation = endFixedRotation;
}
/**
* Sets the app-requested animation type for rotation. Will be one of the
* ROTATION_ANIMATION_ values in {@link android.view.WindowManager.LayoutParams};
*/
public void setRotationAnimation(int anim) {
mRotationAnimation = anim;
}
/** Sets the background color of this change's container. */
public void setBackgroundColor(@ColorInt int backgroundColor) {
mBackgroundColor = backgroundColor;
}
/** Sets a snapshot surface for the "start" state of the container. */
public void setSnapshot(@Nullable SurfaceControl snapshot, float luma) {
mSnapshot = snapshot;
mSnapshotLuma = luma;
}
/** Sets the activity-specific transition information. Container must be an Activity. */
public void setActivityTransitionInfo(@Nullable ActivityTransitionInfo info) {
mActivityTransitionInfo = info;
}
/**
* Sets {@link AnimationOptions} to override animation.
*/
public void setAnimationOptions(@Nullable AnimationOptions options) {
mAnimationOptions = options;
}
/**
* Sets the client-defined TaskFragment token. Only set this if the window is a
* client-organized TaskFragment.
*/
public void setTaskFragmentToken(@Nullable IBinder token) {
mTaskFragmentToken = token;
}
/** @return the container that is changing. May be null if non-remotable (eg. activity) */
@Nullable
public WindowContainerToken getContainer() {
return mContainer;
}
/**
* @return the parent of the changing container. This is the parent within the participants,
* not necessarily the actual parent.
*/
@Nullable
public WindowContainerToken getParent() {
return mParent;
}
/**
* @return the parent of the changing container before the transition if it is reparented
* in the transition. The parent window may not be collected in the transition as a
* participant, and it may have been detached from the display. {@code null} if the changing
* container has not been reparented in the transition, or if the parent is not organizable.
*/
@Nullable
public WindowContainerToken getLastParent() {
return mLastParent;
}
/** @return which action this change represents. */
public @TransitionMode int getMode() {
return mMode;
}
/** @return the flags for this change. */
public @ChangeFlags int getFlags() {
return mFlags;
}
/** Whether this change contains any of the given change flags. */
public boolean hasFlags(@ChangeFlags int flags) {
return (mFlags & flags) != 0;
}
/** Whether this change contains all of the given change flags. */
public boolean hasAllFlags(@ChangeFlags int flags) {
return (mFlags & flags) == flags;
}
/**
* @return the bounds of the container before the change. It may be empty if the container
* is coming into existence.
*/
@NonNull
public Rect getStartAbsBounds() {
return mStartAbsBounds;
}
/**
* @return the bounds of the container after the change. It may be empty if the container
* is disappearing.
*/
@NonNull
public Rect getEndAbsBounds() {
return mEndAbsBounds;
}
/**
* @return the offset of the container's surface from its parent surface after the change.
*/
@NonNull
public Point getEndRelOffset() {
return mEndRelOffset;
}
/**
* Returns the size of parent container after the change.
*/
@NonNull
public Point getEndParentSize() {
return mEndParentSize;
}
/** @return the leash or surface to animate for this container */
@NonNull
public SurfaceControl getLeash() {
return mLeash;
}
/** @return the task info or null if this isn't a task */
@Nullable
public ActivityManager.RunningTaskInfo getTaskInfo() {
return mTaskInfo;
}
public boolean isAllowEnterPip() {
return mAllowEnterPip;
}
public int getStartDisplayId() {
return mStartDisplayId;
}
public int getEndDisplayId() {
return mEndDisplayId;
}
@Surface.Rotation
public int getStartRotation() {
return mStartRotation;
}
@Surface.Rotation
public int getEndRotation() {
return mEndRotation;
}
@Surface.Rotation
public int getEndFixedRotation() {
return mEndFixedRotation;
}
/** @return the rotation animation. */
public int getRotationAnimation() {
return mRotationAnimation;
}
/** @return get the background color of this change's container. */
@ColorInt
public int getBackgroundColor() {
return mBackgroundColor;
}
/** @return a snapshot surface (if applicable). */
@Nullable
public SurfaceControl getSnapshot() {
return mSnapshot;
}
/** @return the luma calculated for the snapshot surface (if applicable). */
public float getSnapshotLuma() {
return mSnapshotLuma;
}
/** @return the component-name of this container (if it is an activity). */
@Nullable
public ComponentName getActivityComponent() {
return mActivityTransitionInfo != null ? mActivityTransitionInfo.getComponent() : null;
}
/**
* @return the activity-specific transition information, or {@code null} if this container
* is not an activity.
*/
@Nullable
public ActivityTransitionInfo getActivityTransitionInfo() {
return mActivityTransitionInfo;
}
/**
* Returns the {@link AnimationOptions}.
*/
@Nullable
public AnimationOptions getAnimationOptions() {
return mAnimationOptions;
}
/**
* Returns the client-defined TaskFragment token. {@code null} if this window is not a
* client-organized TaskFragment.
*/
@Nullable
public IBinder getTaskFragmentToken() {
return mTaskFragmentToken;
}
/** @hide */
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeTypedObject(mContainer, flags);
dest.writeTypedObject(mParent, flags);
dest.writeTypedObject(mLastParent, flags);
mLeash.writeToParcel(dest, flags);
dest.writeInt(mMode);
dest.writeInt(mFlags);
mStartAbsBounds.writeToParcel(dest, flags);
mEndAbsBounds.writeToParcel(dest, flags);
mEndRelOffset.writeToParcel(dest, flags);
mEndParentSize.writeToParcel(dest, flags);
dest.writeTypedObject(mTaskInfo, flags);
dest.writeBoolean(mAllowEnterPip);
dest.writeInt(mStartDisplayId);
dest.writeInt(mEndDisplayId);
dest.writeInt(mStartRotation);
dest.writeInt(mEndRotation);
dest.writeInt(mEndFixedRotation);
dest.writeInt(mRotationAnimation);
dest.writeInt(mBackgroundColor);
dest.writeTypedObject(mSnapshot, flags);
dest.writeFloat(mSnapshotLuma);
dest.writeTypedObject(mActivityTransitionInfo, flags);
dest.writeTypedObject(mAnimationOptions, flags);
dest.writeStrongBinder(mTaskFragmentToken);
}
@NonNull
public static final Creator<Change> CREATOR =
new Creator<Change>() {
@Override
public Change createFromParcel(Parcel in) {
return new Change(in);
}
@Override
public Change[] newArray(int size) {
return new Change[size];
}
};
/** @hide */
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append('{');
if (mContainer != null && !(mContainer.asBinder() instanceof BinderProxy)) {
// Only log the token if it is not a binder proxy and has additional container info
sb.append(mContainer);
sb.append(" ");
}
sb.append("m="); sb.append(modeToString(mMode));
sb.append(" f="); sb.append(flagsToString(mFlags));
if (mParent != null) {
sb.append(" p="); sb.append(mParent);
}
if (mLeash != null) {
sb.append(" leash="); sb.append(mLeash);
}
sb.append(" sb="); sb.append(mStartAbsBounds);
sb.append(" eb="); sb.append(mEndAbsBounds);
if (mEndRelOffset.x != 0 || mEndRelOffset.y != 0) {
sb.append(" eo="); sb.append(mEndRelOffset);
}
if (!mEndParentSize.equals(0, 0)) {
sb.append(" epz=").append(mEndParentSize);
}
sb.append(" d=");
if (mStartDisplayId != mEndDisplayId) {
sb.append(mStartDisplayId).append("->");
}
sb.append(mEndDisplayId);
if (mStartRotation != mEndRotation) {
sb.append(" r="); sb.append(mStartRotation);
sb.append("->"); sb.append(mEndRotation);
sb.append(':'); sb.append(mRotationAnimation);
}
if (mEndFixedRotation != ROTATION_UNDEFINED) {
sb.append(" endFixedRotation="); sb.append(mEndFixedRotation);
}
if (mBackgroundColor != 0) {
sb.append(" bc=").append(Integer.toHexString(mBackgroundColor));
}
if (mSnapshot != null) {
sb.append(" snapshot="); sb.append(mSnapshot);
}
if (mLastParent != null) {
sb.append(" lastParent="); sb.append(mLastParent);
}
if (mActivityTransitionInfo != null) {
sb.append(" activity=").append(mActivityTransitionInfo);
}
if (mTaskInfo != null) {
sb.append(" taskParent=");
sb.append(mTaskInfo.parentTaskId);
sb.append(" winMode=");
sb.append(mTaskInfo.getWindowingMode());
}
if (mAnimationOptions != null) {
sb.append(" opt=").append(mAnimationOptions);
}
if (mTaskFragmentToken != null) {
sb.append(" taskFragmentToken=").append(mTaskFragmentToken);
}
sb.append('}');
return sb.toString();
}
}
/** Represents animation options during a transition */
@SuppressWarnings("UserHandleName")
public static final class AnimationOptions implements Parcelable {
/**
* The default value for animation resources ID, which means to use the system default
* animation.
*/
@SuppressWarnings("ResourceType") // Use as a hint to use the system default animation.
@AnimRes
public static final int DEFAULT_ANIMATION_RESOURCES_ID = 0xFFFFFFFF;
private int mType;
private @AnimRes int mEnterResId = DEFAULT_ANIMATION_RESOURCES_ID;
private @AnimRes int mChangeResId = DEFAULT_ANIMATION_RESOURCES_ID;
private @AnimRes int mExitResId = DEFAULT_ANIMATION_RESOURCES_ID;
private boolean mOverrideTaskTransition;
private String mPackageName;
private final Rect mTransitionBounds = new Rect();
private HardwareBuffer mThumbnail;
private int mAnimations;
// TODO(b/295805497): Extract mBackgroundColor from AnimationOptions
private @ColorInt int mBackgroundColor;
// Customize activity transition animation
private CustomActivityTransition mCustomActivityOpenTransition;
private CustomActivityTransition mCustomActivityCloseTransition;
private int mUserId;
private AnimationOptions(int type) {
mType = type;
}
private AnimationOptions(Parcel in) {
mType = in.readInt();
mEnterResId = in.readInt();
mChangeResId = in.readInt();
mExitResId = in.readInt();
mOverrideTaskTransition = in.readBoolean();
mPackageName = in.readString();
mTransitionBounds.readFromParcel(in);
mThumbnail = in.readTypedObject(HardwareBuffer.CREATOR);
mAnimations = in.readInt();
mCustomActivityOpenTransition = in.readTypedObject(CustomActivityTransition.CREATOR);
mCustomActivityCloseTransition = in.readTypedObject(CustomActivityTransition.CREATOR);
mUserId = in.readInt();
}
/** Make basic customized animation for a package */
@NonNull
public static AnimationOptions makeCommonAnimOptions(@NonNull String packageName) {
AnimationOptions options = new AnimationOptions(ANIM_FROM_STYLE);
options.mPackageName = packageName;
return options;
}
/** Make custom animation from the content of LayoutParams */
@NonNull
public static AnimationOptions makeAnimOptionsFromLayoutParameters(
@NonNull WindowManager.LayoutParams lp) {
AnimationOptions options = new AnimationOptions(ANIM_FROM_STYLE);
options.mPackageName = lp.packageName;
options.mAnimations = lp.windowAnimations;
return options;
}
/** Add customized window animations */
public void addOptionsFromLayoutParameters(@NonNull WindowManager.LayoutParams lp) {
mAnimations = lp.windowAnimations;
}
/** Add customized activity animation attributes */
public void addCustomActivityTransition(boolean isOpen,
int enterResId, int exitResId, int backgroundColor) {
CustomActivityTransition customTransition = isOpen
? mCustomActivityOpenTransition : mCustomActivityCloseTransition;
if (customTransition == null) {
customTransition = new CustomActivityTransition();
if (isOpen) {
mCustomActivityOpenTransition = customTransition;
} else {
mCustomActivityCloseTransition = customTransition;
}
}
customTransition.addCustomActivityTransition(enterResId, exitResId, backgroundColor);
}
/**
* Creates a {@link android.app.ActivityOptions#ANIM_CUSTOM} {@link AnimationOptions}.
*
* @param packageName the package name that includes the animation resources.
* @param enterResId the resources ID of open animation.
* @param changeResId the resources ID of change animation.
* @param exitResId the resources ID of close animation.
* @param overrideTaskTransition indicates whether to override task transition.
*/
@NonNull
public static AnimationOptions makeCustomAnimOptions(@NonNull String packageName,
@AnimRes int enterResId, @AnimRes int changeResId, @AnimRes int exitResId,
boolean overrideTaskTransition) {
AnimationOptions options = new AnimationOptions(ANIM_CUSTOM);
options.mPackageName = packageName;
options.mEnterResId = enterResId;
options.mChangeResId = changeResId;
options.mExitResId = exitResId;
options.mOverrideTaskTransition = overrideTaskTransition;
return options;
}
/** Make options for a clip-reveal animation. */
@NonNull
public static AnimationOptions makeClipRevealAnimOptions(int startX, int startY, int width,
int height) {
AnimationOptions options = new AnimationOptions(ANIM_CLIP_REVEAL);
options.mTransitionBounds.set(startX, startY, startX + width, startY + height);
return options;
}
/** Make options for a scale-up animation with task override option */
@NonNull
public static AnimationOptions makeScaleUpAnimOptions(int startX, int startY, int width,
int height, boolean overrideTaskTransition) {
AnimationOptions options = new AnimationOptions(ANIM_SCALE_UP);
options.mTransitionBounds.set(startX, startY, startX + width, startY + height);
options.mOverrideTaskTransition = overrideTaskTransition;
return options;
}
/** Make options for a thumbnail-scaling animation. */
@NonNull
public static AnimationOptions makeThumbnailAnimOptions(@NonNull HardwareBuffer srcThumb,
int startX, int startY, boolean scaleUp) {
AnimationOptions options = new AnimationOptions(
scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN);
options.mTransitionBounds.set(startX, startY, startX, startY);
options.mThumbnail = srcThumb;
return options;
}
/** Make options for an animation that spans activities of different profiles. */
@NonNull
public static AnimationOptions makeCrossProfileAnimOptions() {
AnimationOptions options = new AnimationOptions(ANIM_OPEN_CROSS_PROFILE_APPS);
return options;
}
/** Make options designating this as a scene-transition animation. */
@NonNull
public static AnimationOptions makeSceneTransitionAnimOptions() {
AnimationOptions options = new AnimationOptions(ANIM_SCENE_TRANSITION);
return options;
}
public void setUserId(int userId) {
mUserId = userId;
}
public int getUserId() {
return mUserId;
}
public int getType() {
return mType;
}
@AnimRes
public int getEnterResId() {
return mEnterResId;
}
@AnimRes
public int getChangeResId() {
return mChangeResId;
}
@AnimRes
public int getExitResId() {
return mExitResId;
}
public boolean getOverrideTaskTransition() {
return mOverrideTaskTransition;
}
@Nullable
public String getPackageName() {
return mPackageName;
}
@NonNull
public Rect getTransitionBounds() {
return mTransitionBounds;
}
@Nullable
public HardwareBuffer getThumbnail() {
return mThumbnail;
}
public int getAnimations() {
return mAnimations;
}
/** Return customized activity transition if existed. */
@Nullable
public CustomActivityTransition getCustomActivityTransition(boolean open) {
return open ? mCustomActivityOpenTransition : mCustomActivityCloseTransition;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mType);
dest.writeInt(mEnterResId);
dest.writeInt(mChangeResId);
dest.writeInt(mExitResId);
dest.writeBoolean(mOverrideTaskTransition);
dest.writeString(mPackageName);
mTransitionBounds.writeToParcel(dest, flags);
dest.writeTypedObject(mThumbnail, flags);
dest.writeInt(mAnimations);
dest.writeTypedObject(mCustomActivityOpenTransition, flags);
dest.writeTypedObject(mCustomActivityCloseTransition, flags);
dest.writeInt(mUserId);
}
@NonNull
public static final Creator<AnimationOptions> CREATOR =
new Creator<AnimationOptions>() {
@Override
public AnimationOptions createFromParcel(Parcel in) {
return new AnimationOptions(in);
}
@Override
public AnimationOptions[] newArray(int size) {
return new AnimationOptions[size];
}
};
/** @hide */
@Override
public int describeContents() {
return 0;
}
@NonNull
private static String typeToString(int mode) {
return switch (mode) {
case ANIM_CUSTOM -> "CUSTOM";
case ANIM_SCALE_UP -> "SCALE_UP";
case ANIM_THUMBNAIL_SCALE_UP -> "THUMBNAIL_SCALE_UP";
case ANIM_THUMBNAIL_SCALE_DOWN -> "THUMBNAIL_SCALE_DOWN";
case ANIM_SCENE_TRANSITION -> "SCENE_TRANSITION";
case ANIM_CLIP_REVEAL -> "CLIP_REVEAL";
case ANIM_OPEN_CROSS_PROFILE_APPS -> "OPEN_CROSS_PROFILE_APPS";
case ANIM_FROM_STYLE -> "FROM_STYLE";
default -> "<" + mode + ">";
};
}
@Override
@NonNull
public String toString() {
final StringBuilder sb = new StringBuilder(32);
sb.append("{t=").append(typeToString(mType));
if (mOverrideTaskTransition) {
sb.append(" overrideTask=true");
}
if (!mTransitionBounds.isEmpty()) {
sb.append(" bounds=").append(mTransitionBounds);
}
if (mEnterResId != DEFAULT_ANIMATION_RESOURCES_ID) {
sb.append(" enterResId=").append(mEnterResId);
}
if (mChangeResId != DEFAULT_ANIMATION_RESOURCES_ID) {
sb.append(" changeResId=").append(mChangeResId);
}
if (mExitResId != DEFAULT_ANIMATION_RESOURCES_ID) {
sb.append(" exitResId=").append(mExitResId);
}
sb.append(" mUserId=").append(mUserId);
sb.append('}');
return sb.toString();
}
/** Customized activity transition. */
public static final class CustomActivityTransition implements Parcelable {
private int mCustomEnterResId;
private int mCustomExitResId;
private int mCustomBackgroundColor;
/** Returns customize activity animation enter resource id */
public int getCustomEnterResId() {
return mCustomEnterResId;
}
/** Returns customize activity animation exit resource id */
public int getCustomExitResId() {
return mCustomExitResId;
}
/** Returns customize activity animation background color */
public int getCustomBackgroundColor() {
return mCustomBackgroundColor;
}
CustomActivityTransition() {}
CustomActivityTransition(Parcel in) {
mCustomEnterResId = in.readInt();
mCustomExitResId = in.readInt();
mCustomBackgroundColor = in.readInt();
}
/** Add customized activity animation attributes */
public void addCustomActivityTransition(
int enterResId, int exitResId, int backgroundColor) {
mCustomEnterResId = enterResId;
mCustomExitResId = exitResId;
mCustomBackgroundColor = backgroundColor;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mCustomEnterResId);
dest.writeInt(mCustomExitResId);
dest.writeInt(mCustomBackgroundColor);
}
@NonNull
public static final Creator<CustomActivityTransition> CREATOR =
new Creator<CustomActivityTransition>() {
@Override
public CustomActivityTransition createFromParcel(Parcel in) {
return new CustomActivityTransition(in);
}
@Override
public CustomActivityTransition[] newArray(int size) {
return new CustomActivityTransition[size];
}
};
}
}
/**
* An animation root in a transition. There is one of these for each display that contains
* participants. It will be placed, in z-order, right above the top-most participant and at the
* same position in the hierarchy. As a result, if all participants are animating within a
* part of the screen, the root-leash will only be in that part of the screen. In these cases,
* it's relative position (from the screen) is stored in {@link Root#getOffset}.
*/
public static final class Root implements Parcelable {
private final int mDisplayId;
private final SurfaceControl mLeash;
private final Point mOffset = new Point();
public Root(int displayId, @NonNull SurfaceControl leash, int offsetLeft, int offsetTop) {
mDisplayId = displayId;
mLeash = leash;
mOffset.set(offsetLeft, offsetTop);
}
private Root(Parcel in) {
mDisplayId = in.readInt();
mLeash = new SurfaceControl();
mLeash.readFromParcel(in);
mLeash.setUnreleasedWarningCallSite("TransitionInfo.Root");
mOffset.readFromParcel(in);
}
private Root localRemoteCopy() {
return new Root(mDisplayId, new SurfaceControl(mLeash, "localRemote"),
mOffset.x, mOffset.y);
}
/** @return the id of the display this root is on. */
public int getDisplayId() {
return mDisplayId;
}
/** @return the root's leash. Surfaces should be parented to this while animating. */
@NonNull
public SurfaceControl getLeash() {
return mLeash;
}
/** @return the offset (relative to its screen) of the root leash. */
@NonNull
public Point getOffset() {
return mOffset;
}
/** @hide */
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mDisplayId);
mLeash.writeToParcel(dest, flags);
mOffset.writeToParcel(dest, flags);
}
@NonNull
public static final Creator<Root> CREATOR =
new Creator<Root>() {
@Override
public Root createFromParcel(Parcel in) {
return new Root(in);
}
@Override
public Root[] newArray(int size) {
return new Root[size];
}
};
/** @hide */
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
return mDisplayId + "@" + mOffset + ":" + mLeash;
}
}
}
|