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