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; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 39 | boolean animateHideSensitive; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 40 | boolean hasDelays; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 41 | boolean hasGoToFullShadeEvent; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 42 | long customDelay; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 43 | private ArraySet<Property> mAnimatedProperties = new ArraySet<>(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 44 | |
| 45 | public AnimationFilter animateAlpha() { |
| 46 | animateAlpha = true; |
| 47 | return this; |
| 48 | } |
| 49 | |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 50 | public AnimationFilter animateScale() { |
| 51 | animate(View.SCALE_X); |
| 52 | animate(View.SCALE_Y); |
| 53 | return this; |
| 54 | } |
| 55 | |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 56 | public AnimationFilter animateX() { |
| 57 | animateX = true; |
| 58 | return this; |
| 59 | } |
| 60 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 61 | public AnimationFilter animateY() { |
| 62 | animateY = true; |
| 63 | return this; |
| 64 | } |
| 65 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 66 | public AnimationFilter hasDelays() { |
| 67 | hasDelays = true; |
| 68 | return this; |
| 69 | } |
| 70 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 71 | public AnimationFilter animateZ() { |
| 72 | animateZ = true; |
| 73 | return this; |
| 74 | } |
| 75 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 76 | public AnimationFilter animateHeight() { |
| 77 | animateHeight = true; |
| 78 | return this; |
| 79 | } |
| 80 | |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 81 | public AnimationFilter animateTopInset() { |
| 82 | animateTopInset = true; |
| 83 | return this; |
| 84 | } |
| 85 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 86 | public AnimationFilter animateDimmed() { |
| 87 | animateDimmed = true; |
| 88 | return this; |
| 89 | } |
| 90 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 91 | public AnimationFilter animateHideSensitive() { |
| 92 | animateHideSensitive = true; |
| 93 | return this; |
| 94 | } |
| 95 | |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 96 | 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 Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 105 | /** |
| 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 Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 114 | NotificationStackScrollLayout.AnimationEvent ev = events.get(i); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 115 | combineFilter(events.get(i).filter); |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 116 | if (ev.animationType == |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 117 | NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 118 | hasGoToFullShadeEvent = true; |
| 119 | } |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 120 | if (ev.animationType == NotificationStackScrollLayout.AnimationEvent |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 121 | .ANIMATION_TYPE_HEADS_UP_DISAPPEAR) { |
| 122 | customDelay = StackStateAnimator.ANIMATION_DELAY_HEADS_UP; |
| 123 | } else if (ev.animationType == NotificationStackScrollLayout.AnimationEvent |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 124 | .ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) { |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 125 | // 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 Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 129 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 133 | public void combineFilter(AnimationFilter filter) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 134 | animateAlpha |= filter.animateAlpha; |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 135 | animateX |= filter.animateX; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 136 | animateY |= filter.animateY; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 137 | animateYViews.addAll(filter.animateYViews); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 138 | animateZ |= filter.animateZ; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 139 | animateHeight |= filter.animateHeight; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 140 | animateTopInset |= filter.animateTopInset; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 141 | animateDimmed |= filter.animateDimmed; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 142 | animateHideSensitive |= filter.animateHideSensitive; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 143 | hasDelays |= filter.hasDelays; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 144 | mAnimatedProperties.addAll(filter.mAnimatedProperties); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 147 | public void reset() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 148 | animateAlpha = false; |
Selim Cinek | c40c79a | 2016-11-08 09:52:52 -0800 | [diff] [blame] | 149 | animateX = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 150 | animateY = false; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 151 | animateYViews.clear(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 152 | animateZ = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 153 | animateHeight = false; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 154 | animateTopInset = false; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 155 | animateDimmed = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 156 | animateHideSensitive = false; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 157 | hasDelays = false; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 158 | hasGoToFullShadeEvent = false; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 159 | customDelay = NO_DELAY; |
Selim Cinek | f082fe2 | 2016-12-20 14:32:19 +0100 | [diff] [blame] | 160 | 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 Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 171 | } |
| 172 | } |