Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.stack; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 18 | |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 19 | import android.util.Property; |
| 20 | import android.view.View; |
| 21 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 22 | import androidx.collection.ArraySet; |
| 23 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | |
| 26 | /** |
| 27 | * Filters the animations for only a certain type of properties. |
| 28 | */ |
| 29 | public class AnimationFilter { |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 30 | public static final int NO_DELAY = -1; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 31 | boolean animateAlpha; |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 32 | boolean animateX; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 33 | boolean animateY; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 34 | ArraySet<View> animateYViews = new ArraySet<>(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 35 | boolean animateZ; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 36 | boolean animateHeight; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 37 | boolean animateTopInset; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 38 | boolean animateDimmed; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 39 | boolean animateDark; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 40 | boolean animateHideSensitive; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 41 | boolean hasDelays; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 42 | boolean hasGoToFullShadeEvent; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 43 | long customDelay; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 44 | private ArraySet<Property> mAnimatedProperties = new ArraySet<>(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 45 | |
| 46 | public AnimationFilter animateAlpha() { |
| 47 | animateAlpha = true; |
| 48 | return this; |
| 49 | } |
| 50 | |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 51 | public AnimationFilter animateScale() { |
| 52 | animate(View.SCALE_X); |
| 53 | animate(View.SCALE_Y); |
| 54 | return this; |
| 55 | } |
| 56 | |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 57 | public AnimationFilter animateX() { |
| 58 | animateX = true; |
| 59 | return this; |
| 60 | } |
| 61 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 62 | public AnimationFilter animateY() { |
| 63 | animateY = true; |
| 64 | return this; |
| 65 | } |
| 66 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 67 | public AnimationFilter hasDelays() { |
| 68 | hasDelays = true; |
| 69 | return this; |
| 70 | } |
| 71 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 72 | public AnimationFilter animateZ() { |
| 73 | animateZ = true; |
| 74 | return this; |
| 75 | } |
| 76 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 77 | public AnimationFilter animateHeight() { |
| 78 | animateHeight = true; |
| 79 | return this; |
| 80 | } |
| 81 | |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 82 | public AnimationFilter animateTopInset() { |
| 83 | animateTopInset = true; |
| 84 | return this; |
| 85 | } |
| 86 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 87 | public AnimationFilter animateDimmed() { |
| 88 | animateDimmed = true; |
| 89 | return this; |
| 90 | } |
| 91 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 92 | public AnimationFilter animateDark() { |
| 93 | animateDark = true; |
| 94 | return this; |
| 95 | } |
| 96 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 97 | public AnimationFilter animateHideSensitive() { |
| 98 | animateHideSensitive = true; |
| 99 | return this; |
| 100 | } |
| 101 | |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 102 | 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 Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 111 | /** |
| 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 Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 120 | NotificationStackScrollLayout.AnimationEvent ev = events.get(i); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 121 | combineFilter(events.get(i).filter); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 122 | if (ev.animationType == |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 123 | NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 124 | hasGoToFullShadeEvent = true; |
| 125 | } |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 126 | if (ev.animationType == NotificationStackScrollLayout.AnimationEvent |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 127 | .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
| 128 | customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP; |
| 129 | } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 130 | .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) { |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 131 | // 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; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 135 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 139 | public void combineFilter(AnimationFilter filter) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 140 | animateAlpha |= filter.animateAlpha; |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 141 | animateX |= filter.animateX; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 142 | animateY |= filter.animateY; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 143 | animateYViews.addAll(filter.animateYViews); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 144 | animateZ |= filter.animateZ; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 145 | animateHeight |= filter.animateHeight; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 146 | animateTopInset |= filter.animateTopInset; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 147 | animateDimmed |= filter.animateDimmed; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 148 | animateDark |= filter.animateDark; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 149 | animateHideSensitive |= filter.animateHideSensitive; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 150 | hasDelays |= filter.hasDelays; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 151 | mAnimatedProperties.addAll(filter.mAnimatedProperties); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 154 | public void reset() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 155 | animateAlpha = false; |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 156 | animateX = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 157 | animateY = false; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 158 | animateYViews.clear(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 159 | animateZ = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 160 | animateHeight = false; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 161 | animateTopInset = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 162 | animateDimmed = false; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 163 | animateDark = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 164 | animateHideSensitive = false; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 165 | hasDelays = false; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 166 | hasGoToFullShadeEvent = false; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 167 | customDelay = NO_DELAY; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 168 | mAnimatedProperties.clear(); |
| 169 | } |
| 170 | |
| 171 | public AnimationFilter animate(Property property) { |
| 172 | mAnimatedProperties.add(property); |
| 173 | return this; |
| 174 | } |
| 175 | |
| 176 | public boolean shouldAnimateProperty(Property property) { |
| 177 | // TODO: migrate all existing animators to properties |
| 178 | return mAnimatedProperties.contains(property); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 179 | } |
| 180 | } |