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
17package com.android.systemui.statusbar.stack;
18
19import java.util.ArrayList;
20
21/**
22 * Filters the animations for only a certain type of properties.
23 */
24public class AnimationFilter {
25    boolean animateAlpha;
26    boolean animateY;
27    boolean animateZ;
28    boolean animateScale;
29    boolean animateHeight;
30    boolean animateTopInset;
31    boolean animateDimmed;
32    boolean animateDark;
33    boolean animateHideSensitive;
34    boolean hasDelays;
35    boolean hasGoToFullShadeEvent;
36    boolean hasDarkEvent;
37    int darkAnimationOriginIndex;
38
39    public AnimationFilter animateAlpha() {
40        animateAlpha = true;
41        return this;
42    }
43
44    public AnimationFilter animateY() {
45        animateY = true;
46        return this;
47    }
48
49    public AnimationFilter hasDelays() {
50        hasDelays = true;
51        return this;
52    }
53
54    public AnimationFilter animateZ() {
55        animateZ = true;
56        return this;
57    }
58
59    public AnimationFilter animateScale() {
60        animateScale = true;
61        return this;
62    }
63
64    public AnimationFilter animateHeight() {
65        animateHeight = true;
66        return this;
67    }
68
69    public AnimationFilter animateTopInset() {
70        animateTopInset = true;
71        return this;
72    }
73
74    public AnimationFilter animateDimmed() {
75        animateDimmed = true;
76        return this;
77    }
78
79    public AnimationFilter animateDark() {
80        animateDark = true;
81        return this;
82    }
83
84    public AnimationFilter animateHideSensitive() {
85        animateHideSensitive = true;
86        return this;
87    }
88
89    /**
90     * Combines multiple filters into {@code this} filter, using or as the operand .
91     *
92     * @param events The animation events from the filters to combine.
93     */
94    public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
95        reset();
96        int size = events.size();
97        for (int i = 0; i < size; i++) {
98            NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
99            combineFilter(events.get(i).filter);
100            if (ev.animationType ==
101                    NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
102                hasGoToFullShadeEvent = true;
103            }
104            if (ev.animationType ==
105                    NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_DARK) {
106                hasDarkEvent = true;
107                darkAnimationOriginIndex = ev.darkAnimationOriginIndex;
108            }
109        }
110    }
111
112    private void combineFilter(AnimationFilter filter) {
113        animateAlpha |= filter.animateAlpha;
114        animateY |= filter.animateY;
115        animateZ |= filter.animateZ;
116        animateScale |= filter.animateScale;
117        animateHeight |= filter.animateHeight;
118        animateTopInset |= filter.animateTopInset;
119        animateDimmed |= filter.animateDimmed;
120        animateDark |= filter.animateDark;
121        animateHideSensitive |= filter.animateHideSensitive;
122        hasDelays |= filter.hasDelays;
123    }
124
125    private void reset() {
126        animateAlpha = false;
127        animateY = false;
128        animateZ = false;
129        animateScale = false;
130        animateHeight = false;
131        animateTopInset = false;
132        animateDimmed = false;
133        animateDark = false;
134        animateHideSensitive = false;
135        hasDelays = false;
136        hasGoToFullShadeEvent = false;
137        hasDarkEvent = false;
138        darkAnimationOriginIndex =
139                NotificationStackScrollLayout.AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE;
140    }
141}
142