• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.systemui.statusbar.notification.stack;
18 
19 import android.util.Property;
20 import android.view.View;
21 
22 import androidx.collection.ArraySet;
23 
24 import java.util.ArrayList;
25 
26 /**
27  * Filters the animations for only a certain type of properties.
28  */
29 public class AnimationFilter {
30     public static final int NO_DELAY = -1;
31     boolean animateAlpha;
32     boolean animateX;
33     boolean animateY;
34     ArraySet<View> animateYViews = new ArraySet<>();
35     boolean animateZ;
36     boolean animateHeight;
37     boolean animateTopInset;
38     boolean animateDimmed;
39     boolean animateDark;
40     boolean animateHideSensitive;
41     boolean hasDelays;
42     boolean hasGoToFullShadeEvent;
43     long customDelay;
44     private ArraySet<Property> mAnimatedProperties = new ArraySet<>();
45 
animateAlpha()46     public AnimationFilter animateAlpha() {
47         animateAlpha = true;
48         return this;
49     }
50 
animateScale()51     public AnimationFilter animateScale() {
52         animate(View.SCALE_X);
53         animate(View.SCALE_Y);
54         return this;
55     }
56 
animateX()57     public AnimationFilter animateX() {
58         animateX = true;
59         return this;
60     }
61 
animateY()62     public AnimationFilter animateY() {
63         animateY = true;
64         return this;
65     }
66 
hasDelays()67     public AnimationFilter hasDelays() {
68         hasDelays = true;
69         return this;
70     }
71 
animateZ()72     public AnimationFilter animateZ() {
73         animateZ = true;
74         return this;
75     }
76 
animateHeight()77     public AnimationFilter animateHeight() {
78         animateHeight = true;
79         return this;
80     }
81 
animateTopInset()82     public AnimationFilter animateTopInset() {
83         animateTopInset = true;
84         return this;
85     }
86 
animateDimmed()87     public AnimationFilter animateDimmed() {
88         animateDimmed = true;
89         return this;
90     }
91 
animateDark()92     public AnimationFilter animateDark() {
93         animateDark = true;
94         return this;
95     }
96 
animateHideSensitive()97     public AnimationFilter animateHideSensitive() {
98         animateHideSensitive = true;
99         return this;
100     }
101 
animateY(View view)102     public AnimationFilter animateY(View view) {
103         animateYViews.add(view);
104         return this;
105     }
106 
shouldAnimateY(View view)107     public boolean shouldAnimateY(View view) {
108         return animateY || animateYViews.contains(view);
109     }
110 
111     /**
112      * Combines multiple filters into {@code this} filter, using or as the operand .
113      *
114      * @param events The animation events from the filters to combine.
115      */
applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events)116     public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
117         reset();
118         int size = events.size();
119         for (int i = 0; i < size; i++) {
120             NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
121             combineFilter(events.get(i).filter);
122             if (ev.animationType ==
123                     NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
124                 hasGoToFullShadeEvent = true;
125             }
126             if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
127                     .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) {
128                 customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
129             } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
130                     .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
131                 // We need both timeouts when clicking, one to delay it and one for the animation
132                 // to look nice
133                 customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP_CLICKED
134                         + StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
135             }
136         }
137     }
138 
combineFilter(AnimationFilter filter)139     public void combineFilter(AnimationFilter filter) {
140         animateAlpha |= filter.animateAlpha;
141         animateX |= filter.animateX;
142         animateY |= filter.animateY;
143         animateYViews.addAll(filter.animateYViews);
144         animateZ |= filter.animateZ;
145         animateHeight |= filter.animateHeight;
146         animateTopInset |= filter.animateTopInset;
147         animateDimmed |= filter.animateDimmed;
148         animateDark |= filter.animateDark;
149         animateHideSensitive |= filter.animateHideSensitive;
150         hasDelays |= filter.hasDelays;
151         mAnimatedProperties.addAll(filter.mAnimatedProperties);
152     }
153 
reset()154     public void reset() {
155         animateAlpha = false;
156         animateX = false;
157         animateY = false;
158         animateYViews.clear();
159         animateZ = false;
160         animateHeight = false;
161         animateTopInset = false;
162         animateDimmed = false;
163         animateDark = false;
164         animateHideSensitive = false;
165         hasDelays = false;
166         hasGoToFullShadeEvent = false;
167         customDelay = NO_DELAY;
168         mAnimatedProperties.clear();
169     }
170 
animate(Property property)171     public AnimationFilter animate(Property property) {
172         mAnimatedProperties.add(property);
173         return this;
174     }
175 
shouldAnimateProperty(Property property)176     public boolean shouldAnimateProperty(Property property) {
177         // TODO: migrate all existing animators to properties
178         return mAnimatedProperties.contains(property);
179     }
180 }
181