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     public boolean animateY;
34     boolean animateZ;
35     boolean animateHeight;
36     boolean animateTopInset;
37     boolean animateHideSensitive;
38     boolean hasDelays;
39     boolean hasGoToFullShadeEvent;
40     long customDelay;
41     private ArraySet<Property> mAnimatedProperties = new ArraySet<>();
42 
animateAlpha()43     public AnimationFilter animateAlpha() {
44         animateAlpha = true;
45         return this;
46     }
47 
animateScale()48     public AnimationFilter animateScale() {
49         animate(View.SCALE_X);
50         animate(View.SCALE_Y);
51         return this;
52     }
53 
animateX()54     public AnimationFilter animateX() {
55         animateX = true;
56         return this;
57     }
58 
animateY()59     public AnimationFilter animateY() {
60         animateY = true;
61         return this;
62     }
63 
hasDelays()64     public AnimationFilter hasDelays() {
65         hasDelays = true;
66         return this;
67     }
68 
animateZ()69     public AnimationFilter animateZ() {
70         animateZ = true;
71         return this;
72     }
73 
animateHeight()74     public AnimationFilter animateHeight() {
75         animateHeight = true;
76         return this;
77     }
78 
animateTopInset()79     public AnimationFilter animateTopInset() {
80         animateTopInset = true;
81         return this;
82     }
83 
animateHideSensitive()84     public AnimationFilter animateHideSensitive() {
85         animateHideSensitive = true;
86         return this;
87     }
88 
shouldAnimateY(View view)89     public boolean shouldAnimateY(View view) {
90         return animateY;
91     }
92 
93     /**
94      * Combines multiple filters into {@code this} filter, using or as the operand .
95      *
96      * @param events The animation events from the filters to combine.
97      */
applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events)98     public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
99         reset();
100         int size = events.size();
101         for (int i = 0; i < size; i++) {
102             NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
103             combineFilter(events.get(i).filter);
104             if (ev.animationType ==
105                     NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
106                 hasGoToFullShadeEvent = true;
107             }
108         }
109     }
110 
combineFilter(AnimationFilter filter)111     public void combineFilter(AnimationFilter filter) {
112         animateAlpha |= filter.animateAlpha;
113         animateX |= filter.animateX;
114         animateY |= filter.animateY;
115         animateZ |= filter.animateZ;
116         animateHeight |= filter.animateHeight;
117         animateTopInset |= filter.animateTopInset;
118         animateHideSensitive |= filter.animateHideSensitive;
119         hasDelays |= filter.hasDelays;
120         mAnimatedProperties.addAll(filter.mAnimatedProperties);
121     }
122 
reset()123     public void reset() {
124         animateAlpha = false;
125         animateX = false;
126         animateY = false;
127         animateZ = false;
128         animateHeight = false;
129         animateTopInset = false;
130         animateHideSensitive = false;
131         hasDelays = false;
132         hasGoToFullShadeEvent = false;
133         customDelay = NO_DELAY;
134         mAnimatedProperties.clear();
135     }
136 
animate(Property property)137     public AnimationFilter animate(Property property) {
138         mAnimatedProperties.add(property);
139         return this;
140     }
141 
shouldAnimateProperty(Property property)142     public boolean shouldAnimateProperty(Property property) {
143         // TODO: migrate all existing animators to properties
144         return mAnimatedProperties.contains(property);
145     }
146 }
147