blob: 6cd2290374628d44b8a42e45e0e43eaeeaff6e44 [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;
Jorim Jaggiae441282014-08-01 02:45:18 +020039 boolean animateHideSensitive;
Selim Cinek8efa6dd2014-05-19 16:27:37 +020040 boolean hasDelays;
Jorim Jaggi60d07c52014-07-31 15:38:21 +020041 boolean hasGoToFullShadeEvent;
Selim Cinek332c23f2018-03-16 17:37:50 -070042 long customDelay;
Selim Cinekf082fe22016-12-20 14:32:19 +010043 private ArraySet<Property> mAnimatedProperties = new ArraySet<>();
Jorim Jaggid552d9d2014-05-07 19:41:13 +020044
45 public AnimationFilter animateAlpha() {
46 animateAlpha = true;
47 return this;
48 }
49
Selim Cinekf082fe22016-12-20 14:32:19 +010050 public AnimationFilter animateScale() {
51 animate(View.SCALE_X);
52 animate(View.SCALE_Y);
53 return this;
54 }
55
Selim Cinekc40c79a2016-11-08 09:52:52 -080056 public AnimationFilter animateX() {
57 animateX = true;
58 return this;
59 }
60
Jorim Jaggid552d9d2014-05-07 19:41:13 +020061 public AnimationFilter animateY() {
62 animateY = true;
63 return this;
64 }
65
Selim Cinek8efa6dd2014-05-19 16:27:37 +020066 public AnimationFilter hasDelays() {
67 hasDelays = true;
68 return this;
69 }
70
Jorim Jaggid552d9d2014-05-07 19:41:13 +020071 public AnimationFilter animateZ() {
72 animateZ = true;
73 return this;
74 }
75
Jorim Jaggid552d9d2014-05-07 19:41:13 +020076 public AnimationFilter animateHeight() {
77 animateHeight = true;
78 return this;
79 }
80
Selim Cinek708a6c12014-05-28 14:16:02 +020081 public AnimationFilter animateTopInset() {
82 animateTopInset = true;
83 return this;
84 }
85
Jorim Jaggid552d9d2014-05-07 19:41:13 +020086 public AnimationFilter animateDimmed() {
87 animateDimmed = true;
88 return this;
89 }
90
Jorim Jaggiae441282014-08-01 02:45:18 +020091 public AnimationFilter animateHideSensitive() {
92 animateHideSensitive = true;
93 return this;
94 }
95
Adrian Roos28f90c72017-05-08 17:24:26 -070096 public AnimationFilter animateY(View view) {
97 animateYViews.add(view);
98 return this;
99 }
100
101 public boolean shouldAnimateY(View view) {
102 return animateY || animateYViews.contains(view);
103 }
104
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200105 /**
106 * Combines multiple filters into {@code this} filter, using or as the operand .
107 *
108 * @param events The animation events from the filters to combine.
109 */
110 public void applyCombination(ArrayList<NotificationStackScrollLayout.AnimationEvent> events) {
111 reset();
112 int size = events.size();
113 for (int i = 0; i < size; i++) {
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100114 NotificationStackScrollLayout.AnimationEvent ev = events.get(i);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200115 combineFilter(events.get(i).filter);
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100116 if (ev.animationType ==
Jorim Jaggi60d07c52014-07-31 15:38:21 +0200117 NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) {
118 hasGoToFullShadeEvent = true;
119 }
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700120 if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
Selim Cinek332c23f2018-03-16 17:37:50 -0700121 .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) {
122 customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
123 } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700124 .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) {
Selim Cinek332c23f2018-03-16 17:37:50 -0700125 // We need both timeouts when clicking, one to delay it and one for the animation
126 // to look nice
127 customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP_CLICKED
128 + StackStateAnimator.ANIMATION_DELAY_HEADS_UP;
Jorim Jaggi5eb67c22015-08-19 19:50:49 -0700129 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200130 }
131 }
132
Selim Cinek2b549f42016-11-22 16:38:51 -0800133 public void combineFilter(AnimationFilter filter) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200134 animateAlpha |= filter.animateAlpha;
Selim Cinekc40c79a2016-11-08 09:52:52 -0800135 animateX |= filter.animateX;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200136 animateY |= filter.animateY;
Adrian Roos28f90c72017-05-08 17:24:26 -0700137 animateYViews.addAll(filter.animateYViews);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200138 animateZ |= filter.animateZ;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200139 animateHeight |= filter.animateHeight;
Selim Cinek708a6c12014-05-28 14:16:02 +0200140 animateTopInset |= filter.animateTopInset;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200141 animateDimmed |= filter.animateDimmed;
Jorim Jaggiae441282014-08-01 02:45:18 +0200142 animateHideSensitive |= filter.animateHideSensitive;
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200143 hasDelays |= filter.hasDelays;
Selim Cinekf082fe22016-12-20 14:32:19 +0100144 mAnimatedProperties.addAll(filter.mAnimatedProperties);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200145 }
146
Selim Cinek2b549f42016-11-22 16:38:51 -0800147 public void reset() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200148 animateAlpha = false;
Selim Cinekc40c79a2016-11-08 09:52:52 -0800149 animateX = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200150 animateY = false;
Adrian Roos28f90c72017-05-08 17:24:26 -0700151 animateYViews.clear();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200152 animateZ = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200153 animateHeight = false;
Selim Cinek708a6c12014-05-28 14:16:02 +0200154 animateTopInset = false;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200155 animateDimmed = false;
Jorim Jaggiae441282014-08-01 02:45:18 +0200156 animateHideSensitive = false;
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200157 hasDelays = false;
Jorim Jaggi60d07c52014-07-31 15:38:21 +0200158 hasGoToFullShadeEvent = false;
Selim Cinek332c23f2018-03-16 17:37:50 -0700159 customDelay = NO_DELAY;
Selim Cinekf082fe22016-12-20 14:32:19 +0100160 mAnimatedProperties.clear();
161 }
162
163 public AnimationFilter animate(Property property) {
164 mAnimatedProperties.add(property);
165 return this;
166 }
167
168 public boolean shouldAnimateProperty(Property property) {
169 // TODO: migrate all existing animators to properties
170 return mAnimatedProperties.contains(property);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200171 }
172}