• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.quickstep.util;
17 
18 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
19 import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat;
20 
21 import java.util.ArrayDeque;
22 import java.util.ArrayList;
23 import java.util.Queue;
24 
25 /**
26  * Holds a collection of RemoteAnimationTargets, filtered by different properties.
27  */
28 public class RemoteAnimationTargetSet {
29 
30     private final Queue<SyncRtSurfaceTransactionApplierCompat> mDependentTransactionAppliers =
31             new ArrayDeque<>(1);
32 
33     public final RemoteAnimationTargetCompat[] unfilteredApps;
34     public final RemoteAnimationTargetCompat[] apps;
35     public final int targetMode;
36     public final boolean hasRecents;
37 
RemoteAnimationTargetSet(RemoteAnimationTargetCompat[] apps, int targetMode)38     public RemoteAnimationTargetSet(RemoteAnimationTargetCompat[] apps, int targetMode) {
39         ArrayList<RemoteAnimationTargetCompat> filteredApps = new ArrayList<>();
40         boolean hasRecents = false;
41         if (apps != null) {
42             for (RemoteAnimationTargetCompat target : apps) {
43                 if (target.mode == targetMode) {
44                     filteredApps.add(target);
45                 }
46 
47                 hasRecents |= target.activityType ==
48                         RemoteAnimationTargetCompat.ACTIVITY_TYPE_RECENTS;
49             }
50         }
51 
52         this.unfilteredApps = apps;
53         this.apps = filteredApps.toArray(new RemoteAnimationTargetCompat[filteredApps.size()]);
54         this.targetMode = targetMode;
55         this.hasRecents = hasRecents;
56     }
57 
findTask(int taskId)58     public RemoteAnimationTargetCompat findTask(int taskId) {
59         for (RemoteAnimationTargetCompat target : apps) {
60             if (target.taskId == taskId) {
61                 return target;
62             }
63         }
64         return null;
65     }
66 
isAnimatingHome()67     public boolean isAnimatingHome() {
68         for (RemoteAnimationTargetCompat target : apps) {
69             if (target.activityType == RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME) {
70                 return true;
71             }
72         }
73         return false;
74     }
75 
addDependentTransactionApplier(SyncRtSurfaceTransactionApplierCompat delay)76     public void addDependentTransactionApplier(SyncRtSurfaceTransactionApplierCompat delay) {
77         mDependentTransactionAppliers.add(delay);
78     }
79 
release()80     public void release() {
81         SyncRtSurfaceTransactionApplierCompat applier = mDependentTransactionAppliers.poll();
82         if (applier == null) {
83             for (RemoteAnimationTargetCompat target : unfilteredApps) {
84                 target.release();
85             }
86         } else {
87             applier.addAfterApplyCallback(this::release);
88         }
89     }
90 }
91