summaryrefslogtreecommitdiff
path: root/quickstep/src/com/android/quickstep/views/TaskView.java
blob: 83a5c7212793110de99022bc6ec1024cad655bc1 (plain)
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
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
/*
 * Copyright (C) 2017 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 com.android.quickstep.views;

import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.widget.Toast.LENGTH_SHORT;

import static com.android.launcher3.LauncherState.BACKGROUND_APP;
import static com.android.launcher3.Utilities.getDescendantCoordRelativeToAncestor;
import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASK_LAUNCH_TAP;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_UNDEFINED;
import static com.android.launcher3.util.SplitConfigurationOptions.getLogEventForPosition;
import static com.android.quickstep.util.BorderAnimator.DEFAULT_BORDER_COLOR;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.IdRes;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.RemoteAnimationTarget;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
import com.android.launcher3.util.TransformingTouchDelegate;
import com.android.launcher3.util.ViewPool.Reusable;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.RemoteAnimationTargets;
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
import com.android.quickstep.TaskAnimationManager;
import com.android.quickstep.TaskIconCache;
import com.android.quickstep.TaskOverlayFactory;
import com.android.quickstep.TaskThumbnailCache;
import com.android.quickstep.TaskUtils;
import com.android.quickstep.TaskViewUtils;
import com.android.quickstep.util.BorderAnimator;
import com.android.quickstep.util.CancellableTask;
import com.android.quickstep.util.RecentsOrientedState;
import com.android.quickstep.util.SplitSelectStateController;
import com.android.quickstep.util.TaskCornerRadius;
import com.android.quickstep.util.TaskRemovedDuringLaunchListener;
import com.android.quickstep.util.TransformParams;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.recents.utilities.PreviewPositionHelper;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;

import java.lang.annotation.Retention;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * A task in the Recents view.
 */
public class TaskView extends FrameLayout implements Reusable {

    private static final String TAG = TaskView.class.getSimpleName();
    private static final boolean DEBUG = false;

    private static final RectF EMPTY_RECT_F = new RectF();

    public static final int FLAG_UPDATE_ICON = 1;
    public static final int FLAG_UPDATE_THUMBNAIL = FLAG_UPDATE_ICON << 1;

    public static final int FLAG_UPDATE_ALL = FLAG_UPDATE_ICON | FLAG_UPDATE_THUMBNAIL;

    /**
     * Used in conjunction with {@link #onTaskListVisibilityChanged(boolean, int)}, providing more
     * granularity on which components of this task require an update
     */
    @Retention(SOURCE)
    @IntDef({FLAG_UPDATE_ALL, FLAG_UPDATE_ICON, FLAG_UPDATE_THUMBNAIL})
    public @interface TaskDataChanges {}

    /**
     * Type of task view
     */
    @Retention(SOURCE)
    @IntDef({Type.SINGLE, Type.GROUPED, Type.DESKTOP})
    public @interface Type {
        int SINGLE = 1;
        int GROUPED = 2;
        int DESKTOP = 3;
    }

    /** The maximum amount that a task view can be scrimmed, dimmed or tinted. */
    public static final float MAX_PAGE_SCRIM_ALPHA = 0.4f;

    private static final float EDGE_SCALE_DOWN_FACTOR_CAROUSEL = 0.03f;
    private static final float EDGE_SCALE_DOWN_FACTOR_GRID = 0.00f;

    public static final long SCALE_ICON_DURATION = 120;
    private static final long DIM_ANIM_DURATION = 700;

    private static final Interpolator GRID_INTERPOLATOR = ACCEL_DEACCEL;

    /**
     * This technically can be a vanilla {@link TouchDelegate} class, however that class requires
     * setting the touch bounds at construction, so we'd repeatedly be created many instances
     * unnecessarily as scrolling occurs, whereas {@link TransformingTouchDelegate} allows touch
     * delegated bounds only to be updated.
     */
    private TransformingTouchDelegate mIconTouchDelegate;

    private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
            Collections.singletonList(new Rect());

    public static final FloatProperty<TaskView> FOCUS_TRANSITION =
            new FloatProperty<TaskView>("focusTransition") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setIconsAndBannersTransitionProgress(v, false /* invert */);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mFocusTransitionProgress;
                }
            };

    private static final FloatProperty<TaskView> SPLIT_SELECT_TRANSLATION_X =
            new FloatProperty<TaskView>("splitSelectTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setSplitSelectTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mSplitSelectTranslationX;
                }
            };

    private static final FloatProperty<TaskView> SPLIT_SELECT_TRANSLATION_Y =
            new FloatProperty<TaskView>("splitSelectTranslationY") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setSplitSelectTranslationY(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mSplitSelectTranslationY;
                }
            };

    private static final FloatProperty<TaskView> DISMISS_TRANSLATION_X =
            new FloatProperty<TaskView>("dismissTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setDismissTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mDismissTranslationX;
                }
            };

    private static final FloatProperty<TaskView> DISMISS_TRANSLATION_Y =
            new FloatProperty<TaskView>("dismissTranslationY") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setDismissTranslationY(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mDismissTranslationY;
                }
            };

    private static final FloatProperty<TaskView> TASK_OFFSET_TRANSLATION_X =
            new FloatProperty<TaskView>("taskOffsetTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setTaskOffsetTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mTaskOffsetTranslationX;
                }
            };

    private static final FloatProperty<TaskView> TASK_OFFSET_TRANSLATION_Y =
            new FloatProperty<TaskView>("taskOffsetTranslationY") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setTaskOffsetTranslationY(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mTaskOffsetTranslationY;
                }
            };

    private static final FloatProperty<TaskView> TASK_RESISTANCE_TRANSLATION_X =
            new FloatProperty<TaskView>("taskResistanceTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setTaskResistanceTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mTaskResistanceTranslationX;
                }
            };

    private static final FloatProperty<TaskView> TASK_RESISTANCE_TRANSLATION_Y =
            new FloatProperty<TaskView>("taskResistanceTranslationY") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setTaskResistanceTranslationY(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mTaskResistanceTranslationY;
                }
            };

    private static final FloatProperty<TaskView> NON_GRID_TRANSLATION_X =
            new FloatProperty<TaskView>("nonGridTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setNonGridTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mNonGridTranslationX;
                }
            };

    private static final FloatProperty<TaskView> NON_GRID_TRANSLATION_Y =
            new FloatProperty<TaskView>("nonGridTranslationY") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setNonGridTranslationY(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mNonGridTranslationY;
                }
            };

    public static final FloatProperty<TaskView> GRID_END_TRANSLATION_X =
            new FloatProperty<TaskView>("gridEndTranslationX") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setGridEndTranslationX(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mGridEndTranslationX;
                }
            };

    public static final FloatProperty<TaskView> SNAPSHOT_SCALE =
            new FloatProperty<TaskView>("snapshotScale") {
                @Override
                public void setValue(TaskView taskView, float v) {
                    taskView.setSnapshotScale(v);
                }

                @Override
                public Float get(TaskView taskView) {
                    return taskView.mSnapshotView.getScaleX();
                }
            };

    @Nullable
    protected Task mTask;
    protected TaskThumbnailView mSnapshotView;
    protected IconView mIconView;
    protected final DigitalWellBeingToast mDigitalWellBeingToast;
    protected float mFullscreenProgress;
    private float mGridProgress;
    protected float mTaskThumbnailSplashAlpha;
    private float mNonGridScale = 1;
    private float mDismissScale = 1;
    protected final FullscreenDrawParams mCurrentFullscreenParams;
    protected final StatefulActivity mActivity;

    // Various causes of changing primary translation, which we aggregate to setTranslationX/Y().
    private float mDismissTranslationX;
    private float mDismissTranslationY;
    private float mTaskOffsetTranslationX;
    private float mTaskOffsetTranslationY;
    private float mTaskResistanceTranslationX;
    private float mTaskResistanceTranslationY;
    // The following translation variables should only be used in the same orientation as Launcher.
    private float mBoxTranslationY;
    // The following grid translations scales with mGridProgress.
    private float mGridTranslationX;
    private float mGridTranslationY;
    // The following grid translation is used to animate closing the gap between grid and clear all.
    private float mGridEndTranslationX;
    // Applied as a complement to gridTranslation, for adjusting the carousel overview and quick
    // switch.
    private float mNonGridTranslationX;
    private float mNonGridTranslationY;
    // Used when in SplitScreenSelectState
    private float mSplitSelectTranslationY;
    private float mSplitSelectTranslationX;

    @Nullable
    private ObjectAnimator mIconAndDimAnimator;
    private float mIconScaleAnimStartProgress = 0;
    private float mFocusTransitionProgress = 1;
    private float mModalness = 0;
    private float mStableAlpha = 1;

    private int mTaskViewId = -1;
    /**
     * Index 0 will contain taskID of left/top task, index 1 will contain taskId of bottom/right
     */
    protected int[] mTaskIdContainer = new int[]{-1, -1};
    protected TaskIdAttributeContainer[] mTaskIdAttributeContainer =
            new TaskIdAttributeContainer[2];

    private boolean mShowScreenshot;

    // The current background requests to load the task thumbnail and icon
    @Nullable
    private CancellableTask mThumbnailLoadRequest;
    @Nullable
    private CancellableTask mIconLoadRequest;

    private boolean mEndQuickswitchCuj;

    private final float[] mIconCenterCoords = new float[2];

    protected final PointF mLastTouchDownPosition = new PointF();

    private boolean mIsClickableAsLiveTile = true;

    @Nullable private final BorderAnimator mBorderAnimator;

    public TaskView(Context context) {
        this(context, null);
    }

    public TaskView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TaskView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public TaskView(
            Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mActivity = StatefulActivity.fromContext(context);
        setOnClickListener(this::onClick);

        mCurrentFullscreenParams = new FullscreenDrawParams(context);
        mDigitalWellBeingToast = new DigitalWellBeingToast(mActivity, this);

        boolean keyboardFocusHighlightEnabled = FeatureFlags.ENABLE_KEYBOARD_QUICK_SWITCH.get()
                || DesktopTaskView.DESKTOP_MODE_SUPPORTED;

        setWillNotDraw(!keyboardFocusHighlightEnabled);

        TypedArray ta = context.obtainStyledAttributes(
                attrs, R.styleable.TaskView, defStyleAttr, defStyleRes);

        mBorderAnimator = !keyboardFocusHighlightEnabled
                ? null
                : new BorderAnimator(
                        /* borderRadiusPx= */ (int) mCurrentFullscreenParams.mCornerRadius,
                        /* borderColor= */ ta.getColor(
                                R.styleable.TaskView_borderColor, DEFAULT_BORDER_COLOR),
                        /* borderAnimationParams= */ new BorderAnimator.SimpleParams(
                                /* borderWidthPx= */ context.getResources().getDimensionPixelSize(
                                        R.dimen.keyboard_quick_switch_border_width),
                                /* boundsBuilder= */ this::updateBorderBounds,
                                /* targetView= */ this));
        ta.recycle();
    }

    protected void updateBorderBounds(Rect bounds) {
        bounds.set(mSnapshotView.getLeft() + Math.round(mSnapshotView.getTranslationX()),
                mSnapshotView.getTop() + Math.round(mSnapshotView.getTranslationY()),
                mSnapshotView.getRight() + Math.round(mSnapshotView.getTranslationX()),
                mSnapshotView.getBottom() + Math.round(mSnapshotView.getTranslationY()));
    }

    public void setTaskViewId(int id) {
        this.mTaskViewId = id;
    }

    public int getTaskViewId() {
        return mTaskViewId;
    }

    /**
     * Builds proto for logging
     */
    public WorkspaceItemInfo getItemInfo() {
        return getItemInfo(mTask);
    }

    protected WorkspaceItemInfo getItemInfo(@Nullable Task task) {
        WorkspaceItemInfo stubInfo = new WorkspaceItemInfo();
        stubInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_TASK;
        stubInfo.container = LauncherSettings.Favorites.CONTAINER_TASKSWITCHER;
        if (task == null) {
            return stubInfo;
        }

        ComponentKey componentKey = TaskUtils.getLaunchComponentKeyForTask(task.key);
        stubInfo.user = componentKey.user;
        stubInfo.intent = new Intent().setComponent(componentKey.componentName);
        stubInfo.title = task.title;
        if (getRecentsView() != null) {
            stubInfo.screenId = getRecentsView().indexOfChild(this);
        }
        return stubInfo;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mSnapshotView = findViewById(R.id.snapshot);
        mIconView = findViewById(R.id.icon);
        mIconTouchDelegate = new TransformingTouchDelegate(mIconView);
    }

    @Override
    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
        if (mBorderAnimator != null) {
            mBorderAnimator.buildAnimator(gainFocus).start();
        }
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (mBorderAnimator != null) {
            mBorderAnimator.drawBorder(canvas);
        }
    }

    /**
     * Whether the taskview should take the touch event from parent. Events passed to children
     * that might require special handling.
     */
    public boolean offerTouchToChildren(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            computeAndSetIconTouchDelegate(mIconView, mIconCenterCoords, mIconTouchDelegate);
        }
        if (mIconTouchDelegate != null && mIconTouchDelegate.onTouchEvent(event)) {
            return true;
        }
        return false;
    }

    protected void computeAndSetIconTouchDelegate(IconView iconView, float[] tempCenterCoords,
            TransformingTouchDelegate transformingTouchDelegate) {
        float iconHalfSize = iconView.getWidth() / 2f;
        tempCenterCoords[0] = tempCenterCoords[1] = iconHalfSize;
        getDescendantCoordRelativeToAncestor(iconView, mActivity.getDragLayer(), tempCenterCoords,
                false);
        transformingTouchDelegate.setBounds(
                (int) (tempCenterCoords[0] - iconHalfSize),
                (int) (tempCenterCoords[1] - iconHalfSize),
                (int) (tempCenterCoords[0] + iconHalfSize),
                (int) (tempCenterCoords[1] + iconHalfSize));
    }

    /**
     * The modalness of this view is how it should be displayed when it is shown on its own in the
     * modal state of overview.
     *
     * @param modalness [0, 1] 0 being in context with other tasks, 1 being shown on its own.
     */
    public void setModalness(float modalness) {
        if (mModalness == modalness) {
            return;
        }
        mModalness = modalness;
        mIconView.setAlpha(1 - modalness);
        mDigitalWellBeingToast.updateBannerOffset(modalness);
    }

    public DigitalWellBeingToast getDigitalWellBeingToast() {
        return mDigitalWellBeingToast;
    }

    /**
     * Updates this task view to the given {@param task}.
     *
     * TODO(b/142282126) Re-evaluate if we need to pass in isMultiWindowMode after
     *   that issue is fixed
     */
    public void bind(Task task, RecentsOrientedState orientedState) {
        cancelPendingLoadTasks();
        mTask = task;
        mTaskIdContainer[0] = mTask.key.id;
        mTaskIdAttributeContainer[0] = new TaskIdAttributeContainer(task, mSnapshotView,
                mIconView, STAGE_POSITION_UNDEFINED);
        mSnapshotView.bind(task);
        setOrientationState(orientedState);
        mDigitalWellBeingToast.initialize(mTask);
    }

    /**
     * Sets up an on-click listener and the visibility for show_windows icon on top of the task.
     */
    public void setUpShowAllInstancesListener() {
        String taskPackageName = mTaskIdAttributeContainer[0].mTask.key.getPackageName();

        // icon of the top/left task
        View showWindowsView = findViewById(R.id.show_windows);
        updateFilterCallback(showWindowsView, getFilterUpdateCallback(taskPackageName));
    }

    /**
     * Returns a callback that updates the state of the filter and the recents overview
     *
     * @param taskPackageName package name of the task to filter by
     */
    @Nullable
    protected View.OnClickListener getFilterUpdateCallback(String taskPackageName) {
        View.OnClickListener cb = (view) -> {
            // update and apply a new filter
            getRecentsView().setAndApplyFilter(taskPackageName);
        };

        if (!getRecentsView().getFilterState().shouldShowFilterUI(taskPackageName)) {
            cb = null;
        }
        return cb;
    }

    /**
     * Sets the correct visibility and callback on the provided filterView based on whether
     * the callback is null or not
     */
    protected void updateFilterCallback(@NonNull View filterView,
            @Nullable View.OnClickListener callback) {
        // Filtering changes alpha instead of the visibility since visibility
        // can be altered separately through RecentsView#resetFromSplitSelectionState()
        if (callback == null) {
            filterView.setAlpha(0);
        } else {
            filterView.setAlpha(1);
        }

        filterView.setOnClickListener(callback);
    }

    public TaskIdAttributeContainer[] getTaskIdAttributeContainers() {
        return mTaskIdAttributeContainer;
    }

    @Nullable
    public Task getTask() {
        return mTask;
    }

    /**
     * Check if given {@code taskId} is tracked in this view
     */
    public boolean containsTaskId(int taskId) {
        return mTask != null && mTask.key.id == taskId;
    }

    /**
     * @return integer array of two elements to be size consistent with max number of tasks possible
     *         index 0 will contain the taskId, index 1 will be -1 indicating a null taskID value
     */
    public int[] getTaskIds() {
        return Arrays.copyOf(mTaskIdContainer, mTaskIdContainer.length);
    }

    public boolean containsMultipleTasks() {
        return mTaskIdContainer[1] != -1;
    }

    /**
     * Returns the TaskIdAttributeContainer corresponding to a given taskId, or null if the TaskView
     * does not contain a Task with that ID.
     */
    @Nullable
    public TaskIdAttributeContainer getTaskAttributesById(int taskId) {
        for (TaskIdAttributeContainer attributes : mTaskIdAttributeContainer) {
            if (attributes.getTask().key.id == taskId) {
                return attributes;
            }
        }

        return null;
    }

    public TaskThumbnailView getThumbnail() {
        return mSnapshotView;
    }

    void refreshThumbnails(@Nullable HashMap<Integer, ThumbnailData> thumbnailDatas) {
        if (mTask != null && thumbnailDatas != null) {
            final ThumbnailData thumbnailData = thumbnailDatas.get(mTask.key.id);
            if (thumbnailData != null) {
                mSnapshotView.setThumbnail(mTask, thumbnailData);
                return;
            }
        }

        mSnapshotView.refresh();
    }

    /** TODO(b/197033698) Remove all usages of above method and migrate to this one */
    public TaskThumbnailView[] getThumbnails() {
        return new TaskThumbnailView[]{mSnapshotView};
    }

    public IconView getIconView() {
        return mIconView;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        RecentsView recentsView = getRecentsView();
        if (recentsView == null || getTask() == null) {
            return false;
        }
        SplitSelectStateController splitSelectStateController =
                recentsView.getSplitSelectController();
        // Disable taps for split selection animation unless we have multiple tasks
        boolean disableTapsForSplitSelect =
                splitSelectStateController.isSplitSelectActive()
                        && splitSelectStateController.getInitialTaskId() == getTask().key.id
                        && !containsMultipleTasks();
        if (disableTapsForSplitSelect) {
            return false;
        }

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mLastTouchDownPosition.set(ev.getX(), ev.getY());
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * @return taskId that split selection was initiated with,
     *         {@link ActivityTaskManager#INVALID_TASK_ID} if no tasks in this TaskView are part of
     *         split selection
     */
    protected int getThisTaskCurrentlyInSplitSelection() {
        SplitSelectStateController splitSelectController =
                getRecentsView().getSplitSelectController();
        int initSplitTaskId = INVALID_TASK_ID;
        for (TaskIdAttributeContainer container : getTaskIdAttributeContainers()) {
            int taskId = container.getTask().key.id;
            if (taskId == splitSelectController.getInitialTaskId()) {
                initSplitTaskId = taskId;
                break;
            }
        }
        return initSplitTaskId;
    }

    private void onClick(View view) {
        if (getTask() == null) {
            return;
        }
        if (confirmSecondSplitSelectApp()) {
            return;
        }
        launchTasks();
        mActivity.getStatsLogManager().logger().withItemInfo(getItemInfo())
                .log(LAUNCHER_TASK_LAUNCH_TAP);
    }

    /**
     * @return {@code true} if user is already in split select mode and this tap was to choose the
     *         second app. {@code false} otherwise
     */
    protected boolean confirmSecondSplitSelectApp() {
        int index = getLastSelectedChildTaskIndex();
        TaskIdAttributeContainer container = mTaskIdAttributeContainer[index];
        if (container != null) {
            return getRecentsView().confirmSplitSelect(this, container.getTask(),
                    container.getIconView().getDrawable(), container.getThumbnailView(),
                    container.getThumbnailView().getThumbnail(), /* intent */ null,
                    /* user */ null);
        }
        return false;
    }

    /**
     * Returns the task index of the last selected child task (0 or 1).
     * If we contain multiple tasks and this TaskView is used as part of split selection, the
     * selected child task index will be that of the remaining task.
     */
    protected int getLastSelectedChildTaskIndex() {
        return 0;
    }

    /**
     * Starts the task associated with this view and animates the startup.
     * @return CompletionStage to indicate the animation completion or null if the launch failed.
     */
    @Nullable
    public RunnableList launchTaskAnimated() {
        if (mTask != null) {
            TestLogging.recordEvent(
                    TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", mTask);
            ActivityOptionsWrapper opts =  mActivity.getActivityLaunchOptions(this, null);
            opts.options.setLaunchDisplayId(
                    getDisplay() == null ? DEFAULT_DISPLAY : getDisplay().getDisplayId());
            if (ActivityManagerWrapper.getInstance()
                    .startActivityFromRecents(mTask.key, opts.options)) {
                RecentsView recentsView = getRecentsView();
                if (recentsView.getRunningTaskViewId() != -1) {
                    recentsView.onTaskLaunchedInLiveTileMode();

                    // Return a fresh callback in the live tile case, so that it's not accidentally
                    // triggered by QuickstepTransitionManager.AppLaunchAnimationRunner.
                    RunnableList callbackList = new RunnableList();
                    recentsView.addSideTaskLaunchCallback(callbackList);
                    return callbackList;
                }
                if (TaskAnimationManager.ENABLE_SHELL_TRANSITIONS) {
                    // If the recents transition is running (ie. in live tile mode), then the start
                    // of a new task will merge into the existing transition and it currently will
                    // not be run independently, so we need to rely on the onTaskAppeared() call
                    // for the new task to trigger the side launch callback to flush this runnable
                    // list (which is usually flushed when the app launch animation finishes)
                    recentsView.addSideTaskLaunchCallback(opts.onEndCallback);
                }
                return opts.onEndCallback;
            } else {
                notifyTaskLaunchFailed(TAG);
                return null;
            }
        } else {
            return null;
        }
    }

    /**
     * Starts the task associated with this view without any animation
     */
    public void launchTask(@NonNull Consumer<Boolean> callback) {
        launchTask(callback, false /* isQuickswitch */);
    }

    /**
     * Starts the task associated with this view without any animation
     */
    public void launchTask(@NonNull Consumer<Boolean> callback, boolean isQuickswitch) {
        if (mTask != null) {
            TestLogging.recordEvent(
                    TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", mTask);

            final TaskRemovedDuringLaunchListener
                    failureListener = new TaskRemovedDuringLaunchListener();
            if (isQuickswitch) {
                // We only listen for failures to launch in quickswitch because the during this
                // gesture launcher is in the background state, vs other launches which are in
                // the actual overview state
                failureListener.register(mActivity, mTask.key.id, () -> {
                    notifyTaskLaunchFailed(TAG);
                    RecentsView rv = getRecentsView();
                    if (rv != null) {
                        // Disable animations for now, as it is an edge case and the app usually
                        // covers launcher and also any state transition animation also gets
                        // clobbered by QuickstepTransitionManager.createWallpaperOpenAnimations
                        // when launcher shows again
                        rv.startHome(false /* animated */);
                        if (rv.mSizeStrategy.getTaskbarController() != null) {
                            // LauncherTaskbarUIController depends on the launcher state when
                            // checking whether to handle resume, but that can come in before
                            // startHome() changes the state, so force-refresh here to ensure the
                            // taskbar is updated
                            rv.mSizeStrategy.getTaskbarController().refreshResumedState();
                        }
                    }
                });
            }
            // Indicate success once the system has indicated that the transition has started
            ActivityOptions opts = ActivityOptions.makeCustomTaskAnimation(getContext(), 0, 0,
                    MAIN_EXECUTOR.getHandler(),
                    elapsedRealTime -> {
                        callback.accept(true);
                    },
                    elapsedRealTime -> {
                        failureListener.onTransitionFinished();
                    });
            opts.setLaunchDisplayId(
                    getDisplay() == null ? DEFAULT_DISPLAY : getDisplay().getDisplayId());
            if (isQuickswitch) {
                opts.setFreezeRecentTasksReordering();
            }
            opts.setDisableStartingWindow(mSnapshotView.shouldShowSplashView());
            Task.TaskKey key = mTask.key;
            UI_HELPER_EXECUTOR.execute(() -> {
                if (!ActivityManagerWrapper.getInstance().startActivityFromRecents(key, opts)) {
                    // If the call to start activity failed, then post the result immediately,
                    // otherwise, wait for the animation start callback from the activity options
                    // above
                    MAIN_EXECUTOR.post(() -> {
                        notifyTaskLaunchFailed(TAG);
                        callback.accept(false);
                    });
                }
            });
        } else {
            callback.accept(false);
        }
    }

    /**
     * Returns ActivityOptions for overriding task transition animation.
     */
    private ActivityOptions makeCustomAnimation(Context context, int enterResId,
            int exitResId, final Runnable callback, final Handler callbackHandler) {
        return ActivityOptions.makeCustomTaskAnimation(context, enterResId, exitResId,
                callbackHandler,
                elapsedRealTime -> {
                    if (callback != null) {
                        callbackHandler.post(callback);
                    }
                }, null /* finishedListener */);
    }

    /**
     * Launch of the current task (both live and inactive tasks) with an animation.
     */
    @Nullable
    public RunnableList launchTasks() {
        RecentsView recentsView = getRecentsView();
        RemoteTargetHandle[] remoteTargetHandles = recentsView.mRemoteTargetHandles;
        if (isRunningTask() && remoteTargetHandles != null) {
            if (!mIsClickableAsLiveTile) {
                Log.e(TAG, "TaskView is not clickable as a live tile; returning to home.");
                return null;
            }

            mIsClickableAsLiveTile = false;
            RemoteAnimationTargets targets;
            if (remoteTargetHandles.length == 1) {
                targets = remoteTargetHandles[0].getTransformParams().getTargetSet();
            } else {
                TransformParams topLeftParams = remoteTargetHandles[0].getTransformParams();
                TransformParams rightBottomParams = remoteTargetHandles[1].getTransformParams();
                RemoteAnimationTarget[] apps = Stream.concat(
                        Arrays.stream(topLeftParams.getTargetSet().apps),
                        Arrays.stream(rightBottomParams.getTargetSet().apps))
                        .toArray(RemoteAnimationTarget[]::new);
                RemoteAnimationTarget[] wallpapers = Stream.concat(
                        Arrays.stream(topLeftParams.getTargetSet().wallpapers),
                        Arrays.stream(rightBottomParams.getTargetSet().wallpapers))
                        .toArray(RemoteAnimationTarget[]::new);
                targets = new RemoteAnimationTargets(apps, wallpapers,
                        topLeftParams.getTargetSet().nonApps,
                        topLeftParams.getTargetSet().targetMode);
            }
            if (targets == null) {
                // If the recents animation is cancelled somehow between the parent if block and
                // here, try to launch the task as a non live tile task.
                RunnableList runnableList = launchTaskAnimated();
                if (runnableList == null) {
                    Log.e(TAG, "Recents animation cancelled and cannot launch task as non-live tile"
                            + "; returning to home");
                }
                mIsClickableAsLiveTile = true;
                return runnableList;
            }

            RunnableList runnableList = new RunnableList();
            AnimatorSet anim = new AnimatorSet();
            TaskViewUtils.composeRecentsLaunchAnimator(
                    anim, this, targets.apps,
                    targets.wallpapers, targets.nonApps, true /* launcherClosing */,
                    mActivity.getStateManager(), recentsView,
                    recentsView.getDepthController());
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    recentsView.runActionOnRemoteHandles(
                            (Consumer<RemoteTargetHandle>) remoteTargetHandle ->
                                    remoteTargetHandle
                                            .getTaskViewSimulator()
                                            .setDrawsBelowRecents(false));
                }

                @Override
                public void onAnimationEnd(Animator animator) {
                    if (mTask != null && mTask.key.displayId != getRootViewDisplayId()) {
                        launchTaskAnimated();
                    }
                    mIsClickableAsLiveTile = true;
                    runEndCallback();
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    runEndCallback();
                }

                private void runEndCallback() {
                    runnableList.executeAllAndDestroy();
                }
            });
            anim.start();
            recentsView.onTaskLaunchedInLiveTileMode();
            return runnableList;
        } else {
            return launchTaskAnimated();
        }
    }

    /**
     * See {@link TaskDataChanges}
     * @param visible If this task view will be visible to the user in overview or hidden
     */
    public void onTaskListVisibilityChanged(boolean visible) {
        onTaskListVisibilityChanged(visible, FLAG_UPDATE_ALL);
    }

    /**
     * See {@link TaskDataChanges}
     * @param visible If this task view will be visible to the user in overview or hidden
     */
    public void onTaskListVisibilityChanged(boolean visible, @TaskDataChanges int changes) {
        if (mTask == null) {
            return;
        }
        cancelPendingLoadTasks();
        if (visible) {
            // These calls are no-ops if the data is already loaded, try and load the high
            // resolution thumbnail if the state permits
            RecentsModel model = RecentsModel.INSTANCE.get(getContext());
            TaskThumbnailCache thumbnailCache = model.getThumbnailCache();
            TaskIconCache iconCache = model.getIconCache();

            if (needsUpdate(changes, FLAG_UPDATE_THUMBNAIL)) {
                mThumbnailLoadRequest = thumbnailCache.updateThumbnailInBackground(
                        mTask, thumbnail -> {
                            mSnapshotView.setThumbnail(mTask, thumbnail);
                        });
            }
            if (needsUpdate(changes, FLAG_UPDATE_ICON)) {
                mIconLoadRequest = iconCache.updateIconInBackground(mTask,
                        (task) -> {
                            setIcon(mIconView, task.icon);
                            mDigitalWellBeingToast.initialize(task);
                        });
            }
        } else {
            if (needsUpdate(changes, FLAG_UPDATE_THUMBNAIL)) {
                mSnapshotView.setThumbnail(null, null);
                // Reset the task thumbnail reference as well (it will be fetched from the cache or
                // reloaded next time we need it)
                mTask.thumbnail = null;
            }
            if (needsUpdate(changes, FLAG_UPDATE_ICON)) {
                setIcon(mIconView, null);
            }
        }
    }

    protected boolean needsUpdate(@TaskDataChanges int dataChange, @TaskDataChanges int flag) {
        return (dataChange & flag) == flag;
    }

    protected void cancelPendingLoadTasks() {
        if (mThumbnailLoadRequest != null) {
            mThumbnailLoadRequest.cancel();
            mThumbnailLoadRequest = null;
        }
        if (mIconLoadRequest != null) {
            mIconLoadRequest.cancel();
            mIconLoadRequest = null;
        }
    }

    private boolean showTaskMenu(IconView iconView) {
        if (!getRecentsView().canLaunchFullscreenTask()) {
            // Don't show menu when selecting second split screen app
            return true;
        }

        if (!mActivity.getDeviceProfile().isTablet
                && !getRecentsView().isClearAllHidden()) {
            getRecentsView().snapToPage(getRecentsView().indexOfChild(this));
            return false;
        } else {
            mActivity.getStatsLogManager().logger().withItemInfo(getItemInfo())
                    .log(LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS);
            return showTaskMenuWithContainer(iconView);
        }
    }

    protected boolean showTaskMenuWithContainer(IconView iconView) {
        TaskIdAttributeContainer menuContainer =
                mTaskIdAttributeContainer[iconView == mIconView ? 0 : 1];
        DeviceProfile dp = mActivity.getDeviceProfile();
        if (dp.isTablet) {
            int alignedOptionIndex = 0;
            if (getRecentsView().isOnGridBottomRow(menuContainer.getTaskView()) && dp.isLandscape) {
                if (FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()) {
                    // With no focused task, there is less available space below the tasks, so align
                    // the arrow to the third option in the menu.
                    alignedOptionIndex = 2;
                } else  {
                    // Bottom row of landscape grid aligns arrow to second option to avoid clipping
                    alignedOptionIndex = 1;
                }
            }
            return TaskMenuViewWithArrow.Companion.showForTask(menuContainer, alignedOptionIndex);
        } else {
            return TaskMenuView.showForTask(menuContainer);
        }
    }

    protected void setIcon(IconView iconView, @Nullable Drawable icon) {
        if (icon != null) {
            iconView.setDrawable(icon);
            iconView.setOnClickListener(v -> {
                if (confirmSecondSplitSelectApp()) {
                    return;
                }
                showTaskMenu(iconView);
            });
            iconView.setOnLongClickListener(v -> {
                requestDisallowInterceptTouchEvent(true);
                return showTaskMenu(iconView);
            });
        } else {
            iconView.setDrawable(null);
            iconView.setOnClickListener(null);
            iconView.setOnLongClickListener(null);
        }
    }

    public void setOrientationState(RecentsOrientedState orientationState) {
        setIconOrientation(orientationState);
        setThumbnailOrientation(orientationState);
    }

    protected void setIconOrientation(RecentsOrientedState orientationState) {
        PagedOrientationHandler orientationHandler = orientationState.getOrientationHandler();
        boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();

        boolean isGridTask = isGridTask();
        LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams();

        int thumbnailTopMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;
        int taskIconHeight = deviceProfile.overviewTaskIconSizePx;
        int taskMargin = deviceProfile.overviewTaskMarginPx;

        orientationHandler.setTaskIconParams(iconParams, taskMargin, taskIconHeight,
                thumbnailTopMargin, isRtl);
        iconParams.width = iconParams.height = taskIconHeight;
        mIconView.setLayoutParams(iconParams);

        mIconView.setRotation(orientationHandler.getDegreesRotated());
        int iconDrawableSize = isGridTask ? deviceProfile.overviewTaskIconDrawableSizeGridPx
                : deviceProfile.overviewTaskIconDrawableSizePx;
        mIconView.setDrawableSize(iconDrawableSize, iconDrawableSize);
    }

    protected void setThumbnailOrientation(RecentsOrientedState orientationState) {
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        int thumbnailTopMargin = deviceProfile.overviewTaskThumbnailTopMarginPx;

        // TODO(b/271468547), we should default to setting trasnlations only on the snapshot instead
        //  of a hybrid of both margins and translations
        LayoutParams snapshotParams = (LayoutParams) mSnapshotView.getLayoutParams();
        snapshotParams.topMargin = thumbnailTopMargin;
        mSnapshotView.setLayoutParams(snapshotParams);

        mSnapshotView.getTaskOverlay().updateOrientationState(orientationState);
        mDigitalWellBeingToast.initialize(mTask);
    }

    /**
     * Returns whether the task is part of overview grid and not being focused.
     */
    public boolean isGridTask() {
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        return deviceProfile.isTablet && !isFocusedTask();
    }

    /** Whether this task view represents the desktop */
    public boolean isDesktopTask() {
        return false;
    }

    /**
     * Called to animate a smooth transition when going directly from an app into Overview (and
     * vice versa). Icons fade in, and DWB banners slide in with a "shift up" animation.
     */
    protected void setIconsAndBannersTransitionProgress(float progress, boolean invert) {
        if (invert) {
            progress = 1 - progress;
        }
        mFocusTransitionProgress = progress;
        float iconScalePercentage = (float) SCALE_ICON_DURATION / DIM_ANIM_DURATION;
        float lowerClamp = invert ? 1f - iconScalePercentage : 0;
        float upperClamp = invert ? 1 : iconScalePercentage;
        float scale = Interpolators.clampToProgress(FAST_OUT_SLOW_IN, lowerClamp, upperClamp)
                .getInterpolation(progress);
        mIconView.setAlpha(scale);
        mDigitalWellBeingToast.updateBannerOffset(1f - scale);
    }

    public void setIconScaleAnimStartProgress(float startProgress) {
        mIconScaleAnimStartProgress = startProgress;
    }

    public void animateIconScaleAndDimIntoView() {
        if (mIconAndDimAnimator != null) {
            mIconAndDimAnimator.cancel();
        }
        mIconAndDimAnimator = ObjectAnimator.ofFloat(this, FOCUS_TRANSITION, 1);
        mIconAndDimAnimator.setCurrentFraction(mIconScaleAnimStartProgress);
        mIconAndDimAnimator.setDuration(DIM_ANIM_DURATION).setInterpolator(LINEAR);
        mIconAndDimAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mIconAndDimAnimator = null;
            }
        });
        mIconAndDimAnimator.start();
    }

    protected void setIconScaleAndDim(float iconScale) {
        setIconScaleAndDim(iconScale, false);
    }

    private void setIconScaleAndDim(float iconScale, boolean invert) {
        if (mIconAndDimAnimator != null) {
            mIconAndDimAnimator.cancel();
        }
        setIconsAndBannersTransitionProgress(iconScale, invert);
    }

    protected void resetPersistentViewTransforms() {
        mNonGridTranslationX = mNonGridTranslationY =
                mGridTranslationX = mGridTranslationY = mBoxTranslationY = 0f;
        resetViewTransforms();
    }

    protected void resetViewTransforms() {
        // fullscreenTranslation and accumulatedTranslation should not be reset, as
        // resetViewTransforms is called during Quickswitch scrolling.
        mDismissTranslationX = mTaskOffsetTranslationX =
                mTaskResistanceTranslationX = mSplitSelectTranslationX = mGridEndTranslationX = 0f;
        mDismissTranslationY = mTaskOffsetTranslationY = mTaskResistanceTranslationY = 0f;
        if (getRecentsView() == null || !getRecentsView().isSplitSelectionActive()) {
            mSplitSelectTranslationY = 0f;
        }

        setSnapshotScale(1f);
        applyTranslationX();
        applyTranslationY();
        setTranslationZ(0);
        setAlpha(mStableAlpha);
        setIconScaleAndDim(1);
        setColorTint(0, 0);
        mSnapshotView.resetViewTransforms();
    }

    public void setStableAlpha(float parentAlpha) {
        mStableAlpha = parentAlpha;
        setAlpha(mStableAlpha);
    }

    @Override
    public void onRecycle() {
        resetPersistentViewTransforms();
        // Clear any references to the thumbnail (it will be re-read either from the cache or the
        // system on next bind)
        mSnapshotView.setThumbnail(mTask, null);
        setOverlayEnabled(false);
        onTaskListVisibilityChanged(false);
    }

    public float getTaskCornerRadius() {
        return mCurrentFullscreenParams.mCornerRadius;
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        if (mActivity.getDeviceProfile().isTablet) {
            setPivotX(getLayoutDirection() == LAYOUT_DIRECTION_RTL ? 0 : right - left);
            setPivotY(mSnapshotView.getTop());
        } else {
            setPivotX((right - left) * 0.5f);
            setPivotY(mSnapshotView.getTop() + mSnapshotView.getHeight() * 0.5f);
        }
        if (Utilities.ATLEAST_Q) {
            SYSTEM_GESTURE_EXCLUSION_RECT.get(0).set(0, 0, getWidth(), getHeight());
            setSystemGestureExclusionRects(SYSTEM_GESTURE_EXCLUSION_RECT);
        }
    }

    /**
     * How much to scale down pages near the edge of the screen.
     */
    public static float getEdgeScaleDownFactor(DeviceProfile deviceProfile) {
        return deviceProfile.isTablet ? EDGE_SCALE_DOWN_FACTOR_GRID
                : EDGE_SCALE_DOWN_FACTOR_CAROUSEL;
    }

    private void setNonGridScale(float nonGridScale) {
        mNonGridScale = nonGridScale;
        applyScale();
    }

    public float getNonGridScale() {
        return mNonGridScale;
    }

    private void setSnapshotScale(float dismissScale) {
        mDismissScale = dismissScale;
        applyScale();
    }

    /**
     * Moves TaskView between carousel and 2 row grid.
     *
     * @param gridProgress 0 = carousel; 1 = 2 row grid.
     */
    public void setGridProgress(float gridProgress) {
        mGridProgress = gridProgress;
        applyTranslationX();
        applyTranslationY();
        applyScale();
    }

    private void applyScale() {
        float scale = 1;
        scale *= getPersistentScale();
        scale *= mDismissScale;
        setScaleX(scale);
        setScaleY(scale);
        updateSnapshotRadius();
    }

    /**
     * Returns multiplication of scale that is persistent (e.g. fullscreen and grid), and does not
     * change according to a temporary state.
     */
    public float getPersistentScale() {
        float scale = 1;
        float gridProgress = GRID_INTERPOLATOR.getInterpolation(mGridProgress);
        scale *= Utilities.mapRange(gridProgress, mNonGridScale, 1f);
        return scale;
    }

    /**
     * Updates alpha of task thumbnail splash on swipe up/down.
     */
    public void setTaskThumbnailSplashAlpha(float taskThumbnailSplashAlpha) {
        mTaskThumbnailSplashAlpha = taskThumbnailSplashAlpha;
        applyThumbnailSplashAlpha();
    }

    protected void applyThumbnailSplashAlpha() {
        mSnapshotView.setSplashAlpha(mTaskThumbnailSplashAlpha);
    }

    protected void refreshTaskThumbnailSplash() {
        mSnapshotView.refreshSplashView();
    }

    private void setSplitSelectTranslationX(float x) {
        mSplitSelectTranslationX = x;
        applyTranslationX();
    }

    private void setSplitSelectTranslationY(float y) {
        mSplitSelectTranslationY = y;
        applyTranslationY();
    }

    private void setDismissTranslationX(float x) {
        mDismissTranslationX = x;
        applyTranslationX();
    }

    private void setDismissTranslationY(float y) {
        mDismissTranslationY = y;
        applyTranslationY();
    }

    private void setTaskOffsetTranslationX(float x) {
        mTaskOffsetTranslationX = x;
        applyTranslationX();
    }

    private void setTaskOffsetTranslationY(float y) {
        mTaskOffsetTranslationY = y;
        applyTranslationY();
    }

    private void setTaskResistanceTranslationX(float x) {
        mTaskResistanceTranslationX = x;
        applyTranslationX();
    }

    private void setTaskResistanceTranslationY(float y) {
        mTaskResistanceTranslationY = y;
        applyTranslationY();
    }

    private void setNonGridTranslationX(float nonGridTranslationX) {
        mNonGridTranslationX = nonGridTranslationX;
        applyTranslationX();
    }

    private void setNonGridTranslationY(float nonGridTranslationY) {
        mNonGridTranslationY = nonGridTranslationY;
        applyTranslationY();
    }

    public void setGridTranslationX(float gridTranslationX) {
        mGridTranslationX = gridTranslationX;
        applyTranslationX();
    }

    public float getGridTranslationX() {
        return mGridTranslationX;
    }

    public void setGridTranslationY(float gridTranslationY) {
        mGridTranslationY = gridTranslationY;
        applyTranslationY();
    }

    public float getGridTranslationY() {
        return mGridTranslationY;
    }

    private void setGridEndTranslationX(float gridEndTranslationX) {
        mGridEndTranslationX = gridEndTranslationX;
        applyTranslationX();
    }

    public float getScrollAdjustment(boolean gridEnabled) {
        float scrollAdjustment = 0;
        if (gridEnabled) {
            scrollAdjustment += mGridTranslationX;
        } else {
            scrollAdjustment += getPrimaryNonGridTranslationProperty().get(this);
        }
        return scrollAdjustment;
    }

    public float getOffsetAdjustment(boolean gridEnabled) {
        return getScrollAdjustment(gridEnabled);
    }

    public float getSizeAdjustment(boolean fullscreenEnabled) {
        float sizeAdjustment = 1;
        if (fullscreenEnabled) {
            sizeAdjustment *= mNonGridScale;
        }
        return sizeAdjustment;
    }

    private void setBoxTranslationY(float boxTranslationY) {
        mBoxTranslationY = boxTranslationY;
        applyTranslationY();
    }

    private void applyTranslationX() {
        setTranslationX(mDismissTranslationX + mTaskOffsetTranslationX + mTaskResistanceTranslationX
                + mSplitSelectTranslationX + mGridEndTranslationX + getPersistentTranslationX());
    }

    private void applyTranslationY() {
        setTranslationY(mDismissTranslationY + mTaskOffsetTranslationY + mTaskResistanceTranslationY
                + mSplitSelectTranslationY + getPersistentTranslationY());
    }

    /**
     * Returns addition of translationX that is persistent (e.g. fullscreen and grid), and does not
     * change according to a temporary state (e.g. task offset).
     */
    public float getPersistentTranslationX() {
        return getNonGridTrans(mNonGridTranslationX) + getGridTrans(mGridTranslationX);
    }

    /**
     * Returns addition of translationY that is persistent (e.g. fullscreen and grid), and does not
     * change according to a temporary state (e.g. task offset).
     */
    public float getPersistentTranslationY() {
        return mBoxTranslationY
                + getNonGridTrans(mNonGridTranslationY)
                + getGridTrans(mGridTranslationY);
    }

    public FloatProperty<TaskView> getPrimarySplitTranslationProperty() {
        return getPagedOrientationHandler().getPrimaryValue(
                SPLIT_SELECT_TRANSLATION_X, SPLIT_SELECT_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getSecondarySplitTranslationProperty() {
        return getPagedOrientationHandler().getSecondaryValue(
                SPLIT_SELECT_TRANSLATION_X, SPLIT_SELECT_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getPrimaryDismissTranslationProperty() {
        return getPagedOrientationHandler().getPrimaryValue(
                DISMISS_TRANSLATION_X, DISMISS_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getSecondaryDismissTranslationProperty() {
        return getPagedOrientationHandler().getSecondaryValue(
                DISMISS_TRANSLATION_X, DISMISS_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getPrimaryTaskOffsetTranslationProperty() {
        return getPagedOrientationHandler().getPrimaryValue(
                TASK_OFFSET_TRANSLATION_X, TASK_OFFSET_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getSecondaryTaskOffsetTranslationProperty() {
        return getPagedOrientationHandler().getSecondaryValue(
                TASK_OFFSET_TRANSLATION_X, TASK_OFFSET_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getTaskResistanceTranslationProperty() {
        return getPagedOrientationHandler().getSecondaryValue(
                TASK_RESISTANCE_TRANSLATION_X, TASK_RESISTANCE_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getPrimaryNonGridTranslationProperty() {
        return getPagedOrientationHandler().getPrimaryValue(
                NON_GRID_TRANSLATION_X, NON_GRID_TRANSLATION_Y);
    }

    public FloatProperty<TaskView> getSecondaryNonGridTranslationProperty() {
        return getPagedOrientationHandler().getSecondaryValue(
                NON_GRID_TRANSLATION_X, NON_GRID_TRANSLATION_Y);
    }

    @Override
    public boolean hasOverlappingRendering() {
        // TODO: Clip-out the icon region from the thumbnail, since they are overlapping.
        return false;
    }

    public boolean isEndQuickswitchCuj() {
        return mEndQuickswitchCuj;
    }

    public void setEndQuickswitchCuj(boolean endQuickswitchCuj) {
        mEndQuickswitchCuj = endQuickswitchCuj;
    }

    private int getExpectedViewHeight(View view) {
        int expectedHeight;
        int h = view.getLayoutParams().height;
        if (h > 0) {
            expectedHeight = h;
        } else {
            int m = MeasureSpec.makeMeasureSpec(MeasureSpec.EXACTLY - 1, MeasureSpec.AT_MOST);
            view.measure(m, m);
            expectedHeight = view.getMeasuredHeight();
        }
        return expectedHeight;
    }

    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);

        info.addAction(
                new AccessibilityNodeInfo.AccessibilityAction(R.string.accessibility_close,
                        getContext().getText(R.string.accessibility_close)));

        final Context context = getContext();
        for (TaskIdAttributeContainer taskContainer : mTaskIdAttributeContainer) {
            if (taskContainer == null) {
                continue;
            }
            for (SystemShortcut s : TaskOverlayFactory.getEnabledShortcuts(this,
                    taskContainer)) {
                info.addAction(s.createAccessibilityAction(context));
            }
        }

        if (mDigitalWellBeingToast.hasLimit()) {
            info.addAction(
                    new AccessibilityNodeInfo.AccessibilityAction(
                            R.string.accessibility_app_usage_settings,
                            getContext().getText(R.string.accessibility_app_usage_settings)));
        }

        final RecentsView recentsView = getRecentsView();
        final AccessibilityNodeInfo.CollectionItemInfo itemInfo =
                AccessibilityNodeInfo.CollectionItemInfo.obtain(
                        0, 1, recentsView.getTaskViewCount() - recentsView.indexOfChild(this) - 1,
                        1, false);
        info.setCollectionItemInfo(itemInfo);
    }

    @Override
    public boolean performAccessibilityAction(int action, Bundle arguments) {
        if (action == R.string.accessibility_close) {
            getRecentsView().dismissTask(this, true /*animateTaskView*/,
                    true /*removeTask*/);
            return true;
        }

        if (action == R.string.accessibility_app_usage_settings) {
            mDigitalWellBeingToast.openAppUsageSettings(this);
            return true;
        }

        for (TaskIdAttributeContainer taskContainer : mTaskIdAttributeContainer) {
            if (taskContainer == null) {
                continue;
            }
            for (SystemShortcut s : TaskOverlayFactory.getEnabledShortcuts(this,
                    taskContainer)) {
                if (s.hasHandlerForAction(action)) {
                    s.onClick(this);
                    return true;
                }
            }
        }

        return super.performAccessibilityAction(action, arguments);
    }

    public RecentsView getRecentsView() {
        return (RecentsView) getParent();
    }

    PagedOrientationHandler getPagedOrientationHandler() {
        return getRecentsView().mOrientationState.getOrientationHandler();
    }

    private void notifyTaskLaunchFailed(String tag) {
        String msg = "Failed to launch task";
        if (mTask != null) {
            msg += " (task=" + mTask.key.baseIntent + " userId=" + mTask.key.userId + ")";
        }
        Log.w(tag, msg);
        Toast.makeText(getContext(), R.string.activity_not_available, LENGTH_SHORT).show();
    }

    /**
     * Hides the icon and shows insets when this TaskView is about to be shown fullscreen.
     *
     * @param progress: 0 = show icon and no insets; 1 = don't show icon and show full insets.
     */
    public void setFullscreenProgress(float progress) {
        progress = Utilities.boundToRange(progress, 0, 1);
        mFullscreenProgress = progress;
        mIconView.setVisibility(progress < 1 ? VISIBLE : INVISIBLE);
        mSnapshotView.getTaskOverlay().setFullscreenProgress(progress);

        // Animate icons and DWB banners in/out, except in QuickSwitch state, when tiles are
        // oversized and banner would look disproportionately large.
        if (mActivity.getStateManager().getState() != BACKGROUND_APP) {
            setIconsAndBannersTransitionProgress(progress, true);
        }

        updateSnapshotRadius();
    }

    protected void updateSnapshotRadius() {
        updateCurrentFullscreenParams(mSnapshotView.getPreviewPositionHelper());
        mSnapshotView.setFullscreenParams(mCurrentFullscreenParams);
    }

    void updateCurrentFullscreenParams(PreviewPositionHelper previewPositionHelper) {
        if (getRecentsView() == null) {
            return;
        }
        mCurrentFullscreenParams.setProgress(mFullscreenProgress, getRecentsView().getScaleX(),
                getScaleX(), getWidth(), mActivity.getDeviceProfile(), previewPositionHelper);
    }

    /**
     * Updates TaskView scaling and translation required to support variable width if enabled, while
     * ensuring TaskView fits into screen in fullscreen.
     */
    void updateTaskSize() {
        ViewGroup.LayoutParams params = getLayoutParams();
        float nonGridScale;
        float boxTranslationY;
        int expectedWidth;
        int expectedHeight;
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        if (deviceProfile.isTablet) {
            final int thumbnailPadding = deviceProfile.overviewTaskThumbnailTopMarginPx;
            final Rect lastComputedTaskSize = getRecentsView().getLastComputedTaskSize();
            final int taskWidth = lastComputedTaskSize.width();
            final int taskHeight = lastComputedTaskSize.height();

            int boxWidth;
            int boxHeight;
            boolean isFocusedTask = isFocusedTask();
            if (isDesktopTask()) {
                Rect lastComputedDesktopTaskSize =
                        getRecentsView().getLastComputedDesktopTaskSize();
                boxWidth = lastComputedDesktopTaskSize.width();
                boxHeight = lastComputedDesktopTaskSize.height();
            } else if (isFocusedTask) {
                // Task will be focused and should use focused task size. Use focusTaskRatio
                // that is associated with the original orientation of the focused task.
                boxWidth = taskWidth;
                boxHeight = taskHeight;
            } else {
                // Otherwise task is in grid, and should use lastComputedGridTaskSize.
                Rect lastComputedGridTaskSize = getRecentsView().getLastComputedGridTaskSize();
                boxWidth = lastComputedGridTaskSize.width();
                boxHeight = lastComputedGridTaskSize.height();
            }

            // Bound width/height to the box size.
            expectedWidth = boxWidth;
            expectedHeight = boxHeight + thumbnailPadding;

            // Scale to to fit task Rect.
            nonGridScale = taskWidth / (float) boxWidth;

            // Align to top of task Rect.
            boxTranslationY = (expectedHeight - thumbnailPadding - taskHeight) / 2.0f;
        } else {
            nonGridScale = 1f;
            boxTranslationY = 0f;
            expectedWidth = ViewGroup.LayoutParams.MATCH_PARENT;
            expectedHeight = ViewGroup.LayoutParams.MATCH_PARENT;
        }

        setNonGridScale(nonGridScale);
        setBoxTranslationY(boxTranslationY);
        if (params.width != expectedWidth || params.height != expectedHeight) {
            params.width = expectedWidth;
            params.height = expectedHeight;
            setLayoutParams(params);
        }
    }

    private float getGridTrans(float endTranslation) {
        float progress = GRID_INTERPOLATOR.getInterpolation(mGridProgress);
        return Utilities.mapRange(progress, 0, endTranslation);
    }

    private float getNonGridTrans(float endTranslation) {
        return endTranslation - getGridTrans(endTranslation);
    }

    public boolean isRunningTask() {
        if (getRecentsView() == null) {
            return false;
        }
        return this == getRecentsView().getRunningTaskView();
    }

    public boolean isFocusedTask() {
        if (getRecentsView() == null) {
            return false;
        }
        return this == getRecentsView().getFocusedTaskView();
    }

    public void setShowScreenshot(boolean showScreenshot) {
        mShowScreenshot = showScreenshot;
    }

    public boolean showScreenshot() {
        if (!isRunningTask()) {
            return true;
        }
        return mShowScreenshot;
    }

    public void setOverlayEnabled(boolean overlayEnabled) {
        mSnapshotView.setOverlayEnabled(overlayEnabled);
    }

    public void initiateSplitSelect(SplitPositionOption splitPositionOption) {
        getRecentsView().initiateSplitSelect(this, splitPositionOption.stagePosition,
                getLogEventForPosition(splitPositionOption.stagePosition));
    }

    /**
     * Set a color tint on the snapshot and supporting views.
     */
    public void setColorTint(float amount, int tintColor) {
        mSnapshotView.setDimAlpha(amount);
        mIconView.setIconColorTint(tintColor, amount);
        mDigitalWellBeingToast.setBannerColorTint(tintColor, amount);
    }


    private int getRootViewDisplayId() {
        Display  display = getRootView().getDisplay();
        return display != null ? display.getDisplayId() : DEFAULT_DISPLAY;
    }

    /**
     *  Sets visibility for the thumbnail and associated elements (DWB banners and action chips).
     *  IconView is unaffected.
     *
     * @param taskId is only used when setting visibility to a non-{@link View#VISIBLE} value
     */
    void setThumbnailVisibility(int visibility, int taskId) {
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (child != mIconView) {
                child.setVisibility(visibility);
            }
        }
    }

    /**
     * We update and subsequently draw these in {@link #setFullscreenProgress(float)}.
     */
    public static class FullscreenDrawParams {

        private final float mCornerRadius;
        private final float mWindowCornerRadius;

        public float mCurrentDrawnCornerRadius;

        public FullscreenDrawParams(Context context) {
            mCornerRadius = TaskCornerRadius.get(context);
            mWindowCornerRadius = QuickStepContract.getWindowCornerRadius(context);

            mCurrentDrawnCornerRadius = mCornerRadius;
        }

        /**
         * Sets the progress in range [0, 1]
         */
        public void setProgress(float fullscreenProgress, float parentScale, float taskViewScale,
                int previewWidth, DeviceProfile dp, PreviewPositionHelper pph) {
            mCurrentDrawnCornerRadius =
                    Utilities.mapRange(fullscreenProgress, mCornerRadius, mWindowCornerRadius)
                            / parentScale / taskViewScale;
        }
    }

    public class TaskIdAttributeContainer {
        private final TaskThumbnailView mThumbnailView;
        private final Task mTask;
        private final IconView mIconView;
        /** Defaults to STAGE_POSITION_UNDEFINED if in not a split screen task view */
        private @SplitConfigurationOptions.StagePosition int mStagePosition;
        @IdRes
        private final int mA11yNodeId;

        public TaskIdAttributeContainer(Task task, TaskThumbnailView thumbnailView,
                IconView iconView, int stagePosition) {
            this.mTask = task;
            this.mThumbnailView = thumbnailView;
            this.mIconView = iconView;
            this.mStagePosition = stagePosition;
            this.mA11yNodeId = (stagePosition == STAGE_POSITION_BOTTOM_OR_RIGHT) ?
                    R.id.split_bottomRight_appInfo : R.id.split_topLeft_appInfo;
        }

        public TaskThumbnailView getThumbnailView() {
            return mThumbnailView;
        }

        public Task getTask() {
            return mTask;
        }

        public WorkspaceItemInfo getItemInfo() {
            return TaskView.this.getItemInfo(mTask);
        }

        public TaskView getTaskView() {
            return TaskView.this;
        }

        public IconView getIconView() {
            return mIconView;
        }

        public int getStagePosition() {
            return mStagePosition;
        }

        void setStagePosition(@SplitConfigurationOptions.StagePosition int stagePosition) {
            this.mStagePosition = stagePosition;
        }

        public int getA11yNodeId() {
            return mA11yNodeId;
        }
    }
}