AnimationFilter.java revision 587cbf30a7be07b502ab78b21c9f4e24370f8fce
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 animateHeight;
29    boolean animateTopInset;
30    boolean animateDimmed;
31    boolean animateDark;
32    boolean animateHideSensitive;
33    boolean hasDelays;
34    boolean hasGoToFullShadeEvent;
35    boolean hasDarkEvent;
36    boolean hasHeadsUpDisappearClickEvent;
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 animateHeight() {
60        animateHeight = true;
61        return this;
62    }
63
64    public AnimationFilter animateTopInset() {
65        animateTopInset = true;
66        return this;
67    }
68
69    public AnimationFilter animateDimmed() {
70        animateDimmed = true;
71        return this;
72    }
73
74    public AnimationFilter animateDark() {
75        animateDark = true;
76        return this;
77    }
78
79    public AnimationFilter animateHideSensitive() {
80        animateHideSensitive = true;
81        return this;
82    }
83
84    /**
85     * Combines multiple filters into {@code this} filter, using or as the operand .
86     *
87     * @param events The animation events from the filters to combine.
88     */
89    public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
90        reset();
91        int size = events.size();
92        for (int i = 0; i < size; i++) {
93            NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
94            combineFilter(events.get(i).filter);
95            if (ev.animationType ==
96                    NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
97                hasGoToFullShadeEvent = true;
98            }
99            if (ev.animationType ==
100                    NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_DARK) {
101                hasDarkEvent = true;
102                darkAnimationOriginIndex = ev.darkAnimationOriginIndex;
103            }
104            if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
105                    .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
106                hasHeadsUpDisappearClickEvent = true;
107            }
108        }
109    }
110
111    private void combineFilter(AnimationFilter filter) {
112        animateAlpha |= filter.animateAlpha;
113        animateY |= filter.animateY;
114        animateZ |= filter.animateZ;
115        animateHeight |= filter.animateHeight;
116        animateTopInset |= filter.animateTopInset;
117        animateDimmed |= filter.animateDimmed;
118        animateDark |= filter.animateDark;
119        animateHideSensitive |= filter.animateHideSensitive;
120        hasDelays |= filter.hasDelays;
121    }
122
123    private void reset() {
124        animateAlpha = false;
125        animateY = false;
126        animateZ = false;
127        animateHeight = false;
128        animateTopInset = false;
129        animateDimmed = false;
130        animateDark = false;
131        animateHideSensitive = false;
132        hasDelays = false;
133        hasGoToFullShadeEvent = false;
134        hasDarkEvent = false;
135        hasHeadsUpDisappearClickEvent = false;
136        darkAnimationOriginIndex =
137                NotificationStackScrollLayout.AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE;
138    }
139}
140