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