Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +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; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 18 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 21 | import android.animation.ValueAnimator; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 22 | import android.util.Property; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 23 | import android.view.View; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 24 | import android.view.animation.Interpolator; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 25 | |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 26 | import com.android.keyguard.KeyguardSliceView; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 27 | import com.android.systemui.Interpolators; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 28 | import com.android.systemui.R; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 29 | import com.android.systemui.statusbar.NotificationShelf; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 30 | import com.android.systemui.statusbar.StatusBarIconView; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 32 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 35 | import java.util.HashSet; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 36 | import java.util.Stack; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * An stack state animator which handles animations to new StackScrollStates |
| 40 | */ |
| 41 | public class StackStateAnimator { |
| 42 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 43 | public static final int ANIMATION_DURATION_STANDARD = 360; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 44 | public static final int ANIMATION_DURATION_WAKEUP = 500; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 45 | public static final int ANIMATION_DURATION_GO_TO_FULL_SHADE = 448; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 46 | public static final int ANIMATION_DURATION_APPEAR_DISAPPEAR = 464; |
Lucas Dupin | fb8bdbb | 2018-12-02 15:09:37 -0800 | [diff] [blame] | 47 | public static final int ANIMATION_DURATION_SWIPE = 260; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 48 | public static final int ANIMATION_DURATION_DIMMED_ACTIVATED = 220; |
Adrian Roos | af06bf2 | 2016-07-15 12:26:49 -0700 | [diff] [blame] | 49 | public static final int ANIMATION_DURATION_CLOSE_REMOTE_INPUT = 150; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 50 | public static final int ANIMATION_DURATION_HEADS_UP_APPEAR = 550; |
| 51 | public static final int ANIMATION_DURATION_HEADS_UP_APPEAR_CLOSED |
| 52 | = (int) (ANIMATION_DURATION_HEADS_UP_APPEAR |
| 53 | * HeadsUpAppearInterpolator.getFractionUntilOvershoot()); |
| 54 | public static final int ANIMATION_DURATION_HEADS_UP_DISAPPEAR = 300; |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 55 | public static final int ANIMATION_DURATION_PULSE_APPEAR = |
| 56 | KeyguardSliceView.DEFAULT_ANIM_DURATION; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 57 | public static final int ANIMATION_DURATION_BLOCKING_HELPER_FADE = 240; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 58 | public static final int ANIMATION_DELAY_PER_ELEMENT_INTERRUPTING = 80; |
| 59 | public static final int ANIMATION_DELAY_PER_ELEMENT_MANUAL = 32; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 60 | public static final int ANIMATION_DELAY_PER_ELEMENT_GO_TO_FULL_SHADE = 48; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 61 | public static final int DELAY_EFFECT_MAX_INDEX_DIFFERENCE = 2; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 62 | public static final int ANIMATION_DELAY_HEADS_UP = 120; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 63 | public static final int ANIMATION_DELAY_HEADS_UP_CLICKED= 120; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 64 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 65 | private final int mGoToFullShadeAppearingTranslation; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 66 | private final int mPulsingAppearingTranslation; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 67 | private final ExpandableViewState mTmpState = new ExpandableViewState(); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 68 | private final AnimationProperties mAnimationProperties; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 69 | public NotificationStackScrollLayout mHostLayout; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 70 | private ArrayList<NotificationStackScrollLayout.AnimationEvent> mNewEvents = |
| 71 | new ArrayList<>(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 72 | private ArrayList<View> mNewAddChildren = new ArrayList<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 73 | private HashSet<View> mHeadsUpAppearChildren = new HashSet<>(); |
| 74 | private HashSet<View> mHeadsUpDisappearChildren = new HashSet<>(); |
| 75 | private HashSet<Animator> mAnimatorSet = new HashSet<>(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 76 | private Stack<AnimatorListenerAdapter> mAnimationListenerPool = new Stack<>(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 77 | private AnimationFilter mAnimationFilter = new AnimationFilter(); |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 78 | private long mCurrentLength; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 79 | private long mCurrentAdditionalDelay; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 80 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 81 | /** The current index for the last child which was not added in this event set. */ |
| 82 | private int mCurrentLastNotAddedIndex; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 83 | private ValueAnimator mTopOverScrollAnimator; |
| 84 | private ValueAnimator mBottomOverScrollAnimator; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 85 | private int mHeadsUpAppearHeightBottom; |
| 86 | private boolean mShadeExpanded; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 87 | private ArrayList<ExpandableView> mTransientViewsToRemove = new ArrayList<>(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 88 | private NotificationShelf mShelf; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 89 | private float mStatusBarIconLocation; |
| 90 | private int[] mTmpLocation = new int[2]; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 91 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 92 | public StackStateAnimator(NotificationStackScrollLayout hostLayout) { |
| 93 | mHostLayout = hostLayout; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 94 | mGoToFullShadeAppearingTranslation = |
| 95 | hostLayout.getContext().getResources().getDimensionPixelSize( |
| 96 | R.dimen.go_to_full_shade_appearing_translation); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 97 | mPulsingAppearingTranslation = |
| 98 | hostLayout.getContext().getResources().getDimensionPixelSize( |
| 99 | R.dimen.pulsing_notification_appear_translation); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 100 | mAnimationProperties = new AnimationProperties() { |
| 101 | @Override |
| 102 | public AnimationFilter getAnimationFilter() { |
| 103 | return mAnimationFilter; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public AnimatorListenerAdapter getAnimationFinishListener() { |
| 108 | return getGlobalAnimationFinishedListener(); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public boolean wasAdded(View view) { |
| 113 | return mNewAddChildren.contains(view); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public Interpolator getCustomInterpolator(View child, Property property) { |
| 118 | if (mHeadsUpAppearChildren.contains(child) && View.TRANSLATION_Y.equals(property)) { |
Selim Cinek | 061d907 | 2016-12-20 13:17:03 +0100 | [diff] [blame] | 119 | return Interpolators.HEADS_UP_APPEAR; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 120 | } |
| 121 | return null; |
| 122 | } |
| 123 | }; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | public boolean isRunning() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 127 | return !mAnimatorSet.isEmpty(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | public void startAnimationForEvents( |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 131 | ArrayList<NotificationStackScrollLayout.AnimationEvent> mAnimationEvents, |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 132 | long additionalDelay) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 133 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 134 | processAnimationEvents(mAnimationEvents); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 135 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 136 | int childCount = mHostLayout.getChildCount(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 137 | mAnimationFilter.applyCombination(mNewEvents); |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 138 | mCurrentAdditionalDelay = additionalDelay; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 139 | mCurrentLength = NotificationStackScrollLayout.AnimationEvent.combineLength(mNewEvents); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 140 | mCurrentLastNotAddedIndex = findLastNotAddedIndex(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 141 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 142 | final ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 143 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 144 | ExpandableViewState viewState = child.getViewState(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 145 | if (viewState == null || child.getVisibility() == View.GONE |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 146 | || applyWithoutAnimation(child, viewState)) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 147 | continue; |
| 148 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 149 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 150 | initAnimationProperties(child, viewState); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 151 | viewState.animateTo(child, mAnimationProperties); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 152 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 153 | if (!isRunning()) { |
| 154 | // no child has preformed any animation, lets finish |
| 155 | onAnimationFinished(); |
| 156 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 157 | mHeadsUpAppearChildren.clear(); |
| 158 | mHeadsUpDisappearChildren.clear(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 159 | mNewEvents.clear(); |
| 160 | mNewAddChildren.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 163 | private void initAnimationProperties(ExpandableView child, |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 164 | ExpandableViewState viewState) { |
| 165 | boolean wasAdded = mAnimationProperties.wasAdded(child); |
| 166 | mAnimationProperties.duration = mCurrentLength; |
| 167 | adaptDurationWhenGoingToFullShade(child, viewState, wasAdded); |
| 168 | mAnimationProperties.delay = 0; |
| 169 | if (wasAdded || mAnimationFilter.hasDelays |
| 170 | && (viewState.yTranslation != child.getTranslationY() |
| 171 | || viewState.zTranslation != child.getTranslationZ() |
| 172 | || viewState.alpha != child.getAlpha() |
| 173 | || viewState.height != child.getActualHeight() |
| 174 | || viewState.clipTopAmount != child.getClipTopAmount() |
Selim Cinek | ff2ffec | 2018-11-19 18:52:01 -0800 | [diff] [blame] | 175 | || viewState.dark != child.isDark())) { |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 176 | mAnimationProperties.delay = mCurrentAdditionalDelay |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 177 | + calculateChildAnimationDelay(viewState); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | private void adaptDurationWhenGoingToFullShade(ExpandableView child, |
| 182 | ExpandableViewState viewState, boolean wasAdded) { |
| 183 | if (wasAdded && mAnimationFilter.hasGoToFullShadeEvent) { |
| 184 | child.setTranslationY(child.getTranslationY() + mGoToFullShadeAppearingTranslation); |
| 185 | float longerDurationFactor = viewState.notGoneIndex - mCurrentLastNotAddedIndex; |
| 186 | longerDurationFactor = (float) Math.pow(longerDurationFactor, 0.7f); |
| 187 | mAnimationProperties.duration = ANIMATION_DURATION_APPEAR_DISAPPEAR + 50 + |
| 188 | (long) (100 * longerDurationFactor); |
| 189 | } |
| 190 | } |
| 191 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Determines if a view should not perform an animation and applies it directly. |
| 194 | * |
| 195 | * @return true if no animation should be performed |
| 196 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 197 | private boolean applyWithoutAnimation(ExpandableView child, ExpandableViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 198 | if (mShadeExpanded) { |
| 199 | return false; |
| 200 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 201 | if (ViewState.isAnimatingY(child)) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 202 | // A Y translation animation is running |
| 203 | return false; |
| 204 | } |
| 205 | if (mHeadsUpDisappearChildren.contains(child) || mHeadsUpAppearChildren.contains(child)) { |
| 206 | // This is a heads up animation |
| 207 | return false; |
| 208 | } |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 209 | if (NotificationStackScrollLayout.isPinnedHeadsUp(child)) { |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 210 | // This is another headsUp which might move. Let's animate! |
| 211 | return false; |
| 212 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 213 | viewState.applyToView(child); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 214 | return true; |
| 215 | } |
| 216 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 217 | private int findLastNotAddedIndex() { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 218 | int childCount = mHostLayout.getChildCount(); |
| 219 | for (int i = childCount - 1; i >= 0; i--) { |
| 220 | final ExpandableView child = (ExpandableView) mHostLayout.getChildAt(i); |
| 221 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 222 | ExpandableViewState viewState = child.getViewState(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 223 | if (viewState == null || child.getVisibility() == View.GONE) { |
| 224 | continue; |
| 225 | } |
| 226 | if (!mNewAddChildren.contains(child)) { |
| 227 | return viewState.notGoneIndex; |
| 228 | } |
| 229 | } |
| 230 | return -1; |
| 231 | } |
| 232 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 233 | private long calculateChildAnimationDelay(ExpandableViewState viewState) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 234 | if (mAnimationFilter.hasGoToFullShadeEvent) { |
| 235 | return calculateDelayGoToFullShade(viewState); |
| 236 | } |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 237 | if (mAnimationFilter.customDelay != AnimationFilter.NO_DELAY) { |
| 238 | return mAnimationFilter.customDelay; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 239 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 240 | long minDelay = 0; |
| 241 | for (NotificationStackScrollLayout.AnimationEvent event : mNewEvents) { |
| 242 | long delayPerElement = ANIMATION_DELAY_PER_ELEMENT_INTERRUPTING; |
| 243 | switch (event.animationType) { |
| 244 | case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_ADD: { |
| 245 | int ownIndex = viewState.notGoneIndex; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 246 | int changingIndex = |
| 247 | ((ExpandableView) (event.mChangingView)).getViewState().notGoneIndex; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 248 | int difference = Math.abs(ownIndex - changingIndex); |
| 249 | difference = Math.max(0, Math.min(DELAY_EFFECT_MAX_INDEX_DIFFERENCE, |
| 250 | difference - 1)); |
| 251 | long delay = (DELAY_EFFECT_MAX_INDEX_DIFFERENCE - difference) * delayPerElement; |
| 252 | minDelay = Math.max(delay, minDelay); |
| 253 | break; |
| 254 | } |
| 255 | case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT: |
| 256 | delayPerElement = ANIMATION_DELAY_PER_ELEMENT_MANUAL; |
| 257 | case NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE: { |
| 258 | int ownIndex = viewState.notGoneIndex; |
| 259 | boolean noNextView = event.viewAfterChangingView == null; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 260 | ExpandableView viewAfterChangingView = noNextView |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 261 | ? mHostLayout.getLastChildNotGone() |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 262 | : (ExpandableView) event.viewAfterChangingView; |
Selim Cinek | 0c87f87 | 2016-12-13 13:01:20 -0800 | [diff] [blame] | 263 | if (viewAfterChangingView == null) { |
| 264 | // This can happen when the last view in the list is removed. |
| 265 | // Since the shelf is still around and the only view, the code still goes |
| 266 | // in here and tries to calculate the delay for it when case its properties |
| 267 | // have changed. |
| 268 | continue; |
| 269 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 270 | int nextIndex = viewAfterChangingView.getViewState().notGoneIndex; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 271 | if (ownIndex >= nextIndex) { |
| 272 | // we only have the view afterwards |
| 273 | ownIndex++; |
| 274 | } |
| 275 | int difference = Math.abs(ownIndex - nextIndex); |
| 276 | difference = Math.max(0, Math.min(DELAY_EFFECT_MAX_INDEX_DIFFERENCE, |
| 277 | difference - 1)); |
| 278 | long delay = difference * delayPerElement; |
| 279 | minDelay = Math.max(delay, minDelay); |
| 280 | break; |
| 281 | } |
| 282 | default: |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | return minDelay; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 289 | private long calculateDelayGoToFullShade(ExpandableViewState viewState) { |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 290 | int shelfIndex = mShelf.getNotGoneIndex(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 291 | float index = viewState.notGoneIndex; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 292 | long result = 0; |
| 293 | if (index > shelfIndex) { |
| 294 | float diff = index - shelfIndex; |
| 295 | diff = (float) Math.pow(diff, 0.7f); |
| 296 | result += (long) (diff * ANIMATION_DELAY_PER_ELEMENT_GO_TO_FULL_SHADE * 0.25); |
| 297 | index = shelfIndex; |
| 298 | } |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 299 | index = (float) Math.pow(index, 0.7f); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 300 | result += (long) (index * ANIMATION_DELAY_PER_ELEMENT_GO_TO_FULL_SHADE); |
| 301 | return result; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Selim Cinek | 3961054 | 2014-04-30 18:57:47 +0200 | [diff] [blame] | 304 | /** |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 305 | * @return an adapter which ensures that onAnimationFinished is called once no animation is |
| 306 | * running anymore |
| 307 | */ |
| 308 | private AnimatorListenerAdapter getGlobalAnimationFinishedListener() { |
| 309 | if (!mAnimationListenerPool.empty()) { |
| 310 | return mAnimationListenerPool.pop(); |
| 311 | } |
| 312 | |
| 313 | // We need to create a new one, no reusable ones found |
| 314 | return new AnimatorListenerAdapter() { |
| 315 | private boolean mWasCancelled; |
| 316 | |
| 317 | @Override |
| 318 | public void onAnimationEnd(Animator animation) { |
| 319 | mAnimatorSet.remove(animation); |
| 320 | if (mAnimatorSet.isEmpty() && !mWasCancelled) { |
| 321 | onAnimationFinished(); |
| 322 | } |
| 323 | mAnimationListenerPool.push(this); |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public void onAnimationCancel(Animator animation) { |
| 328 | mWasCancelled = true; |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public void onAnimationStart(Animator animation) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 333 | mWasCancelled = false; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 334 | mAnimatorSet.add(animation); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 335 | } |
| 336 | }; |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 339 | private void onAnimationFinished() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 340 | mHostLayout.onChildAnimationFinished(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 341 | |
| 342 | for (ExpandableView transientViewsToRemove : mTransientViewsToRemove) { |
| 343 | transientViewsToRemove.getTransientContainer() |
| 344 | .removeTransientView(transientViewsToRemove); |
| 345 | } |
| 346 | mTransientViewsToRemove.clear(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Process the animationEvents for a new animation |
| 351 | * |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 352 | * @param animationEvents the animation events for the animation to perform |
Selim Cinek | 3961054 | 2014-04-30 18:57:47 +0200 | [diff] [blame] | 353 | */ |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 354 | private void processAnimationEvents( |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 355 | ArrayList<NotificationStackScrollLayout.AnimationEvent> animationEvents) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 356 | for (NotificationStackScrollLayout.AnimationEvent event : animationEvents) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 357 | final ExpandableView changingView = (ExpandableView) event.mChangingView; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 358 | if (event.animationType == |
| 359 | NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_ADD) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 360 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 361 | // This item is added, initialize it's properties. |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 362 | ExpandableViewState viewState = changingView.getViewState(); |
Selim Cinek | 69594fb | 2018-05-18 12:06:10 -0700 | [diff] [blame] | 363 | if (viewState == null || viewState.gone) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 364 | // The position for this child was never generated, let's continue. |
| 365 | continue; |
Selim Cinek | 3961054 | 2014-04-30 18:57:47 +0200 | [diff] [blame] | 366 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 367 | viewState.applyToView(changingView); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 368 | mNewAddChildren.add(changingView); |
| 369 | |
| 370 | } else if (event.animationType == |
| 371 | NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 372 | if (changingView.getVisibility() != View.VISIBLE) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 373 | removeTransientView(changingView); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 374 | continue; |
| 375 | } |
| 376 | |
| 377 | // Find the amount to translate up. This is needed in order to understand the |
| 378 | // direction of the remove animation (either downwards or upwards) |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 379 | // upwards by default |
| 380 | float translationDirection = -1.0f; |
Selim Cinek | b1a8130 | 2018-11-30 14:41:32 -0800 | [diff] [blame] | 381 | if (event.viewAfterChangingView != null) { |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 382 | float ownPosition = changingView.getTranslationY(); |
| 383 | if (changingView instanceof ExpandableNotificationRow |
| 384 | && event.viewAfterChangingView instanceof ExpandableNotificationRow) { |
| 385 | ExpandableNotificationRow changingRow = |
| 386 | (ExpandableNotificationRow) changingView; |
| 387 | ExpandableNotificationRow nextRow = |
| 388 | (ExpandableNotificationRow) event.viewAfterChangingView; |
| 389 | if (changingRow.isRemoved() |
| 390 | && changingRow.wasChildInGroupWhenRemoved() |
| 391 | && !nextRow.isChildInGroup()) { |
| 392 | // the next row isn't actually a child from a group! Let's |
| 393 | // compare absolute positions! |
| 394 | ownPosition = changingRow.getTranslationWhenRemoved(); |
| 395 | } |
| 396 | } |
Selim Cinek | b1a8130 | 2018-11-30 14:41:32 -0800 | [diff] [blame] | 397 | int actualHeight = changingView.getActualHeight(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 398 | // there was a view after this one, Approximate the distance the next child |
| 399 | // travelled |
Selim Cinek | b1a8130 | 2018-11-30 14:41:32 -0800 | [diff] [blame] | 400 | ExpandableViewState viewState = |
| 401 | ((ExpandableView) event.viewAfterChangingView).getViewState(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 402 | translationDirection = ((viewState.yTranslation |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 403 | - (ownPosition + actualHeight / 2.0f)) * 2 / |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 404 | actualHeight); |
| 405 | translationDirection = Math.max(Math.min(translationDirection, 1.0f),-1.0f); |
| 406 | |
| 407 | } |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 408 | changingView.performRemoveAnimation(ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 409 | 0 /* delay */, translationDirection, false /* isHeadsUpAppear */, |
| 410 | 0, () -> removeTransientView(changingView), null); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 411 | } else if (event.animationType == |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 412 | NotificationStackScrollLayout.AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT) { |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 413 | if (Math.abs(changingView.getTranslation()) == changingView.getWidth() |
| 414 | && changingView.getTransientContainer() != null) { |
| 415 | changingView.getTransientContainer().removeTransientView(changingView); |
| 416 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 417 | } else if (event.animationType == NotificationStackScrollLayout |
| 418 | .AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 419 | ExpandableNotificationRow row = (ExpandableNotificationRow) event.mChangingView; |
| 420 | row.prepareExpansionChanged(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 421 | } else if (event.animationType == NotificationStackScrollLayout |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 422 | .AnimationEvent.ANIMATION_TYPE_PULSE_APPEAR) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 423 | ExpandableViewState viewState = changingView.getViewState(); |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 424 | if (viewState != null) { |
| 425 | mTmpState.copyFrom(viewState); |
| 426 | mTmpState.yTranslation += mPulsingAppearingTranslation; |
| 427 | mTmpState.alpha = 0; |
| 428 | mTmpState.applyToView(changingView); |
| 429 | } |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 430 | } else if (event.animationType == NotificationStackScrollLayout |
| 431 | .AnimationEvent.ANIMATION_TYPE_PULSE_DISAPPEAR) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 432 | ExpandableViewState viewState = changingView.getViewState(); |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 433 | if (viewState != null) { |
| 434 | viewState.alpha = 0; |
| 435 | // We want to animate the alpha away before the view starts translating, |
| 436 | // otherwise everything will overlap and look xtra ugly. |
| 437 | float originalYTranslation = viewState.yTranslation; |
| 438 | viewState.yTranslation = changingView.getTranslationY(); |
| 439 | mAnimationFilter.animateAlpha = true; |
| 440 | mAnimationProperties.duration = ANIMATION_DURATION_PULSE_APPEAR / 2; |
| 441 | viewState.animateTo(changingView, mAnimationProperties); |
| 442 | viewState.yTranslation = originalYTranslation; |
| 443 | } |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 444 | } else if (event.animationType == NotificationStackScrollLayout |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 445 | .AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR) { |
| 446 | // This item is added, initialize it's properties. |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 447 | ExpandableViewState viewState = changingView.getViewState(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 448 | mTmpState.copyFrom(viewState); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 449 | if (event.headsUpFromBottom) { |
| 450 | mTmpState.yTranslation = mHeadsUpAppearHeightBottom; |
| 451 | } else { |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 452 | mTmpState.yTranslation = 0; |
| 453 | changingView.performAddAnimation(0, ANIMATION_DURATION_HEADS_UP_APPEAR_CLOSED, |
| 454 | true /* isHeadsUpAppear */); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 455 | } |
| 456 | mHeadsUpAppearChildren.add(changingView); |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 457 | mTmpState.applyToView(changingView); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 458 | } else if (event.animationType == NotificationStackScrollLayout |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 459 | .AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR || |
| 460 | event.animationType == NotificationStackScrollLayout |
| 461 | .AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 462 | mHeadsUpDisappearChildren.add(changingView); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 463 | Runnable endRunnable = null; |
| 464 | // We need some additional delay in case we were removed to make sure we're not |
| 465 | // lagging |
| 466 | int extraDelay = event.animationType == NotificationStackScrollLayout |
| 467 | .AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 468 | ? ANIMATION_DELAY_HEADS_UP_CLICKED |
| 469 | : 0; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 470 | if (changingView.getParent() == null) { |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 471 | // This notification was actually removed, so we need to add it transiently |
| 472 | mHostLayout.addTransientView(changingView, 0); |
| 473 | changingView.setTransientContainer(mHostLayout); |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 474 | mTmpState.initFrom(changingView); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 475 | mTmpState.yTranslation = 0; |
Selim Cinek | 8f93763 | 2015-06-05 15:22:42 +0200 | [diff] [blame] | 476 | // We temporarily enable Y animations, the real filter will be combined |
| 477 | // afterwards anyway |
| 478 | mAnimationFilter.animateY = true; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 479 | mAnimationProperties.delay = extraDelay + ANIMATION_DELAY_HEADS_UP; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 480 | mAnimationProperties.duration = ANIMATION_DURATION_HEADS_UP_DISAPPEAR; |
| 481 | mTmpState.animateTo(changingView, mAnimationProperties); |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 482 | endRunnable = () -> removeTransientView(changingView); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 483 | } |
| 484 | float targetLocation = 0; |
| 485 | boolean needsAnimation = true; |
| 486 | if (changingView instanceof ExpandableNotificationRow) { |
| 487 | ExpandableNotificationRow row = (ExpandableNotificationRow) changingView; |
| 488 | if (row.isDismissed()) { |
| 489 | needsAnimation = false; |
| 490 | } |
| 491 | StatusBarIconView icon = row.getEntry().icon; |
| 492 | if (icon.getParent() != null) { |
| 493 | icon.getLocationOnScreen(mTmpLocation); |
| 494 | float iconPosition = mTmpLocation[0] - icon.getTranslationX() |
| 495 | + ViewState.getFinalTranslationX(icon) + icon.getWidth() * 0.25f; |
| 496 | mHostLayout.getLocationOnScreen(mTmpLocation); |
| 497 | targetLocation = iconPosition - mTmpLocation[0]; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | if (needsAnimation) { |
| 502 | // We need to add the global animation listener, since once no animations are |
| 503 | // running anymore, the panel will instantly hide itself. We need to wait until |
| 504 | // the animation is fully finished for this though. |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 505 | long removeAnimationDelay = changingView.performRemoveAnimation( |
| 506 | ANIMATION_DURATION_HEADS_UP_DISAPPEAR + ANIMATION_DELAY_HEADS_UP, |
| 507 | extraDelay, 0.0f, true /* isHeadsUpAppear */, targetLocation, |
| 508 | endRunnable, getGlobalAnimationFinishedListener()); |
| 509 | mAnimationProperties.delay += removeAnimationDelay; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 510 | } else if (endRunnable != null) { |
| 511 | endRunnable.run(); |
Selim Cinek | 8f93763 | 2015-06-05 15:22:42 +0200 | [diff] [blame] | 512 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 513 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 514 | mNewEvents.add(event); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 515 | } |
| 516 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 517 | |
Selim Cinek | 9dd0d04 | 2018-05-14 18:12:42 -0700 | [diff] [blame] | 518 | public static void removeTransientView(ExpandableView viewToRemove) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 519 | if (viewToRemove.getTransientContainer() != null) { |
| 520 | viewToRemove.getTransientContainer().removeTransientView(viewToRemove); |
| 521 | } |
| 522 | } |
| 523 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 524 | public void animateOverScrollToAmount(float targetAmount, final boolean onTop, |
| 525 | final boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 526 | final float startOverScrollAmount = mHostLayout.getCurrentOverScrollAmount(onTop); |
Jorim Jaggi | 9012958 | 2014-06-02 14:44:49 +0200 | [diff] [blame] | 527 | if (targetAmount == startOverScrollAmount) { |
| 528 | return; |
| 529 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 530 | cancelOverScrollAnimators(onTop); |
| 531 | ValueAnimator overScrollAnimator = ValueAnimator.ofFloat(startOverScrollAmount, |
| 532 | targetAmount); |
| 533 | overScrollAnimator.setDuration(ANIMATION_DURATION_STANDARD); |
| 534 | overScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 535 | @Override |
| 536 | public void onAnimationUpdate(ValueAnimator animation) { |
| 537 | float currentOverScroll = (float) animation.getAnimatedValue(); |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 538 | mHostLayout.setOverScrollAmount( |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 539 | currentOverScroll, onTop, false /* animate */, false /* cancelAnimators */, |
| 540 | isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 541 | } |
| 542 | }); |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 543 | overScrollAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 544 | overScrollAnimator.addListener(new AnimatorListenerAdapter() { |
| 545 | @Override |
| 546 | public void onAnimationEnd(Animator animation) { |
| 547 | if (onTop) { |
| 548 | mTopOverScrollAnimator = null; |
| 549 | } else { |
| 550 | mBottomOverScrollAnimator = null; |
| 551 | } |
| 552 | } |
| 553 | }); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 554 | overScrollAnimator.start(); |
| 555 | if (onTop) { |
| 556 | mTopOverScrollAnimator = overScrollAnimator; |
| 557 | } else { |
| 558 | mBottomOverScrollAnimator = overScrollAnimator; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | public void cancelOverScrollAnimators(boolean onTop) { |
| 563 | ValueAnimator currentAnimator = onTop ? mTopOverScrollAnimator : mBottomOverScrollAnimator; |
| 564 | if (currentAnimator != null) { |
| 565 | currentAnimator.cancel(); |
| 566 | } |
| 567 | } |
Selim Cinek | 02af41e | 2014-10-14 15:46:43 +0200 | [diff] [blame] | 568 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 569 | public void setHeadsUpAppearHeightBottom(int headsUpAppearHeightBottom) { |
| 570 | mHeadsUpAppearHeightBottom = headsUpAppearHeightBottom; |
| 571 | } |
| 572 | |
| 573 | public void setShadeExpanded(boolean shadeExpanded) { |
| 574 | mShadeExpanded = shadeExpanded; |
| 575 | } |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 576 | |
| 577 | public void setShelf(NotificationShelf shelf) { |
| 578 | mShelf = shelf; |
| 579 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 580 | } |