blob: 507cf079e1f3b0a99d7c57ffe367f94ce2e0bd71 [file] [log] [blame]
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.stack;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020018
Selim Cinekf082fe22016-12-20 14:32:19 +010019import android.util.Property;
20import android.view.View;
21
Gus Prevasab336792018-11-14 13:52:20 -050022import androidx.collection.ArraySet;
23
Jorim Jaggid552d9d2014-05-07 19:41:13 +020024import java.util.ArrayList;
25
26/**
27 * Filters the animations for only a certain type of properties.
28 */
29public class AnimationFilter {
Selim Cinek332c23f2018-03-16 17:37:50 -070030 public static final int NO_DELAY = -1;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020031 boolean animateAlpha;
Selim Cinekc40c79a2016-11-08 09:52:52 -080032 boolean animateX;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020033 boolean animateY;
Adrian Roos28f90c72017-05-08 17:24:26 -070034 ArraySet<View> animateYViews = new ArraySet<>();
Jorim Jaggid552d9d2014-05-07 19:41:13 +020035 boolean animateZ;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020036 boolean animateHeight;
Selim Cinek708a6c12014-05-28 14:16:02 +020037 boolean animateTopInset;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020038 boolean animateDimmed;
John Spurlockbf370992014-06-17 13:58:31 -040039 boolean animateDark;
Jorim Jaggiae441282014-08-01 02:45:18 +020040 boolean animateHideSensitive;
Selim Cinek8efa6dd2014-05-19 16:27:37 +020041 boolean hasDelays;
Jorim Jaggi60d07c52014-07-31 15:38:21 +020042 boolean hasGoToFullShadeEvent;
Selim Cinek332c23f2018-03-16 17:37:50 -070043 long customDelay;
Selim Cinekf082fe22016-12-20 14:32:19 +010044 private ArraySet<Property> mAnimatedProperties = new ArraySet<>();
Jorim Jaggid552d9d2014-05-07 19:41:13 +020045
46 public AnimationFilter animateAlpha() {
47 animateAlpha = true;
48 return this;
49 }
50
Selim Cinekf082fe22016-12-20 14:32:19 +010051 public AnimationFilter animateScale() {
52 animate(View.SCALE_X);
53 animate(View.SCALE_Y);
54 return this;
55 }
56
Selim Cinekc40c79a2016-11-08 09:52:52 -080057 public AnimationFilter animateX() {
58 animateX = true;
59 return this;
60 }
61
Jorim Jaggid552d9d2014-05-07 19:41:13 +020062 public AnimationFilter animateY() {
63 animateY = true;
64 return this;
65 }
66
Selim Cinek8efa6dd2014-05-19 16:27:37 +020067 public AnimationFilter hasDelays() {
68 hasDelays = true;
69 return this;
70 }
71
Jorim Jaggid552d9d2014-05-07 19:41:13 +020072 public AnimationFilter animateZ() {
73 animateZ = true;
74 return this;
75 }
76
Jorim Jaggid552d9d2014-05-07 19:41:13 +020077 public AnimationFilter animateHeight() {
78 animateHeight = true;
79 return this;
80 }
81
Selim Cinek708a6c12014-05-28 14:16:02 +020082 public AnimationFilter animateTopInset() {
83 animateTopInset = true;
84 return this;
85 }
86
Jorim Jaggid552d9d2014-05-07 19:41:13 +020087 public AnimationFilter animateDimmed() {
88 animateDimmed = true;
89 return this;
90 }
91
John Spurlockbf370992014-06-17 13:58:31 -040092 public AnimationFilter animateDark() {
93 animateDark = true;
94 return this;
95 }
96
Jorim Jaggiae441282014-08-01 02:45:18 +020097 public AnimationFilter animateHideSensitive() {
98 animateHideSensitive = true;
99 return this;
100 }
101
Adrian Roos28f90c72017-05-08 17:24:26 -0700102 public AnimationFilter animateY(View view) {
103 animateYViews.add(view);
104 return this;
105 }
106
107 public boolean shouldAnimateY(View view) {
108 return animateY || animateYViews.contains(view);
109 }
110
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200111 /**
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 */
116 public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
117 reset();
118 int size = events.size();
119 for (int i = 0; i < size; i++) {
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100120 NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200121 combineFilter(events.get(i).filter);
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100122 if (ev.animationType ==
Jorim Jaggi60d07c52014-07-31 15:38:21 +0200123 NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
124 hasGoToFullShadeEvent = true;
125 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700126 if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
Selim Cinek332c23f2018-03-16 17:37:50 -0700127 .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) {
128 customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
129 } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700130 .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
Selim Cinek332c23f2018-03-16 17:37:50 -0700131 // 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;
Lucas Dupin2a6bdfd2018-06-12 17:45:21 -0700135 } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
136 .ANIMATION_TYPE_PULSE_APPEAR || ev.animationType ==
137 NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_PULSE_DISAPPEAR) {
138 customDelay = StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR / 2;
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700139 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200140 }
141 }
142
Selim Cinek2b549f42016-11-22 16:38:51 -0800143 public void combineFilter(AnimationFilter filter) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200144 animateAlpha |= filter.animateAlpha;
Selim Cinekc40c79a2016-11-08 09:52:52 -0800145 animateX |= filter.animateX;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200146 animateY |= filter.animateY;
Adrian Roos28f90c72017-05-08 17:24:26 -0700147 animateYViews.addAll(filter.animateYViews);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200148 animateZ |= filter.animateZ;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200149 animateHeight |= filter.animateHeight;
Selim Cinek708a6c12014-05-28 14:16:02 +0200150 animateTopInset |= filter.animateTopInset;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200151 animateDimmed |= filter.animateDimmed;
John Spurlockbf370992014-06-17 13:58:31 -0400152 animateDark |= filter.animateDark;
Jorim Jaggiae441282014-08-01 02:45:18 +0200153 animateHideSensitive |= filter.animateHideSensitive;
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200154 hasDelays |= filter.hasDelays;
Selim Cinekf082fe22016-12-20 14:32:19 +0100155 mAnimatedProperties.addAll(filter.mAnimatedProperties);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200156 }
157
Selim Cinek2b549f42016-11-22 16:38:51 -0800158 public void reset() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200159 animateAlpha = false;
Selim Cinekc40c79a2016-11-08 09:52:52 -0800160 animateX = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200161 animateY = false;
Adrian Roos28f90c72017-05-08 17:24:26 -0700162 animateYViews.clear();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200163 animateZ = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200164 animateHeight = false;
Selim Cinek708a6c12014-05-28 14:16:02 +0200165 animateTopInset = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200166 animateDimmed = false;
John Spurlockbf370992014-06-17 13:58:31 -0400167 animateDark = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200168 animateHideSensitive = false;
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200169 hasDelays = false;
Jorim Jaggi60d07c52014-07-31 15:38:21 +0200170 hasGoToFullShadeEvent = false;
Selim Cinek332c23f2018-03-16 17:37:50 -0700171 customDelay = NO_DELAY;
Selim Cinekf082fe22016-12-20 14:32:19 +0100172 mAnimatedProperties.clear();
173 }
174
175 public AnimationFilter animate(Property property) {
176 mAnimatedProperties.add(property);
177 return this;
178 }
179
180 public boolean shouldAnimateProperty(Property property) {
181 // TODO: migrate all existing animators to properties
182 return mAnimatedProperties.contains(property);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200183 }
184}