blob: 54811f5783ae951c092c6c38bfc8671359b4463f [file] [log] [blame]
Selim Cinek67b22602014-03-10 15:40:16 +01001/*
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
17package com.android.systemui.statusbar.stack;
18
Julia Reynoldsed1c9af2018-03-21 15:21:09 -040019import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator
20 .ExpandAnimationParameters;
Selim Cinek2627d722018-01-19 12:16:49 -080021
Selim Cinek614576e2016-01-20 10:54:09 -080022import android.animation.Animator;
23import android.animation.AnimatorListenerAdapter;
24import android.animation.ObjectAnimator;
25import android.animation.PropertyValuesHolder;
Selim Cinekd35c2792016-01-21 13:20:57 -080026import android.animation.TimeAnimator;
27import android.animation.ValueAnimator;
Mady Mellor4b80b102016-01-22 08:03:58 -080028import android.animation.ValueAnimator.AnimatorUpdateListener;
Selim Cinek31d37b92016-04-26 09:56:42 -070029import android.annotation.FloatRange;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +010030import android.annotation.Nullable;
Selim Cinek67b22602014-03-10 15:40:16 +010031import android.content.Context;
32import android.content.res.Configuration;
Anthony Chen3cb3ad92016-12-01 10:58:47 -080033import android.content.res.Resources;
Selim Cinek67b22602014-03-10 15:40:16 +010034import android.graphics.Canvas;
Lucas Dupind285cf02018-01-18 09:18:23 -080035import android.graphics.Color;
Selim Cinek67b22602014-03-10 15:40:16 +010036import android.graphics.Paint;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +010037import android.graphics.PointF;
Selim Cinek6811d722016-01-19 17:53:12 -080038import android.graphics.PorterDuff;
39import android.graphics.PorterDuffXfermode;
40import android.graphics.Rect;
Selim Cinekc22fff62016-05-20 12:44:30 -070041import android.os.Bundle;
Mady Mellor4b80b102016-01-22 08:03:58 -080042import android.os.Handler;
Mady Mellor95d743c2017-01-10 12:05:27 -080043import android.service.notification.StatusBarNotification;
Aurimas Liutikasa14377a2018-04-17 09:50:46 -070044import androidx.annotation.NonNull;
45import androidx.annotation.VisibleForTesting;
46import androidx.core.graphics.ColorUtils;
Selim Cinek67b22602014-03-10 15:40:16 +010047import android.util.AttributeSet;
48import android.util.Log;
Lucas Dupind285cf02018-01-18 09:18:23 -080049import android.util.MathUtils;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070050import android.util.Pair;
Lucas Dupine17ce522017-07-17 15:45:06 -070051import android.view.ContextThemeWrapper;
Selim Cinek11e33232016-08-05 15:30:53 -070052import android.view.InputDevice;
Selim Cinek67b22602014-03-10 15:40:16 +010053import android.view.MotionEvent;
54import android.view.VelocityTracker;
55import android.view.View;
56import android.view.ViewConfiguration;
57import android.view.ViewGroup;
Selim Cinek343e6e22014-04-11 21:23:30 +020058import android.view.ViewTreeObserver;
Adrian Roos5153d4a2016-03-22 10:01:56 -070059import android.view.WindowInsets;
Selim Cinekc22fff62016-05-20 12:44:30 -070060import android.view.accessibility.AccessibilityEvent;
61import android.view.accessibility.AccessibilityNodeInfo;
Selim Cinek572bbd42014-04-25 16:43:27 +020062import android.view.animation.AnimationUtils;
Selim Cinek614576e2016-01-20 10:54:09 -080063import android.view.animation.Interpolator;
Selim Cinek67b22602014-03-10 15:40:16 +010064import android.widget.OverScroller;
Selim Cinek41fe89a2016-06-02 15:27:56 -070065import android.widget.ScrollView;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -070066
Mady Mellora41587b2016-02-11 18:43:06 -080067import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010068import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070069import com.android.keyguard.KeyguardSliceView;
Lucas Dupine17ce522017-07-17 15:45:06 -070070import com.android.settingslib.Utils;
Rohan Shah524cf7b2018-03-15 14:40:02 -070071import com.android.systemui.Dependency;
Selim Cinek67b22602014-03-10 15:40:16 +010072import com.android.systemui.ExpandHelper;
Winsonc0d70582016-01-29 10:24:39 -080073import com.android.systemui.Interpolators;
Selim Cinek67b22602014-03-10 15:40:16 +010074import com.android.systemui.R;
75import com.android.systemui.SwipeHelper;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070076import com.android.systemui.classifier.FalsingManager;
Mady Mellor95d743c2017-01-10 12:05:27 -080077import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
78import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
79import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper;
Selim Cineka32ab602014-06-11 15:06:01 +020080import com.android.systemui.statusbar.ActivatableNotificationView;
Jorim Jaggia2052ea2014-08-05 16:22:30 +020081import com.android.systemui.statusbar.EmptyShadeView;
Selim Cinek67b22602014-03-10 15:40:16 +010082import com.android.systemui.statusbar.ExpandableNotificationRow;
Jorim Jaggibe565df2014-04-28 17:51:23 +020083import com.android.systemui.statusbar.ExpandableView;
Julia Reynoldsed1c9af2018-03-21 15:21:09 -040084import com.android.systemui.statusbar.FooterView;
Rohan Shah524cf7b2018-03-15 14:40:02 -070085import com.android.systemui.statusbar.NotificationBlockingHelperManager;
Adrian Roos7d062c42017-03-30 15:11:43 -070086import com.android.systemui.statusbar.NotificationData;
Mady Mellor7a9b2a62016-03-23 07:41:47 -070087import com.android.systemui.statusbar.NotificationGuts;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090088import com.android.systemui.statusbar.NotificationListContainer;
89import com.android.systemui.statusbar.NotificationLogger;
Selim Cinek0cfbef42016-11-09 19:06:36 -080090import com.android.systemui.statusbar.NotificationShelf;
Mady Mellorc2dbe492017-03-30 13:22:03 -070091import com.android.systemui.statusbar.NotificationSnooze;
Selim Cinek3a9c10a2014-10-28 14:21:10 +010092import com.android.systemui.statusbar.StackScrollerDecorView;
Selim Cinekcb2b6732014-09-05 16:17:22 +020093import com.android.systemui.statusbar.StatusBarState;
Selim Cinek33223572016-02-19 19:32:22 -080094import com.android.systemui.statusbar.notification.FakeShadowView;
Selim Cinek42357e02016-02-24 18:48:01 -080095import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cineka7d4f822016-12-06 14:34:47 -080096import com.android.systemui.statusbar.notification.VisibilityLocationProvider;
Lucas Dupinb561eda2018-04-09 17:25:04 -070097import com.android.systemui.statusbar.phone.DozeParameters;
Selim Cinekf0c79e12018-05-14 17:17:31 -070098import com.android.systemui.statusbar.phone.HeadsUpAppearanceController;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090099import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
Selim Cinekb5605e52015-02-20 18:21:41 +0100100import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinek9bfc7a52018-06-11 16:09:00 -0700101import com.android.systemui.statusbar.phone.NotificationIconAreaController;
Selim Cinekaac93252015-04-14 20:04:12 -0700102import com.android.systemui.statusbar.phone.ScrimController;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800103import com.android.systemui.statusbar.phone.StatusBar;
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900104import com.android.systemui.statusbar.policy.HeadsUpUtil;
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100105import com.android.systemui.statusbar.policy.ScrollAdapter;
Selim Cinek67b22602014-03-10 15:40:16 +0100106
Selim Cinek707e2072017-06-30 18:32:40 +0200107import java.io.FileDescriptor;
108import java.io.PrintWriter;
Selim Cinek572bbd42014-04-25 16:43:27 +0200109import java.util.ArrayList;
Selim Cinek33223572016-02-19 19:32:22 -0800110import java.util.Collections;
111import java.util.Comparator;
Jorim Jaggiff9c9c42014-08-01 05:36:22 +0200112import java.util.HashSet;
Selim Cinekef8c2252017-02-10 14:52:18 -0800113import java.util.List;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800114import java.util.function.BiConsumer;
Selim Cinek572bbd42014-04-25 16:43:27 +0200115
Selim Cinek67b22602014-03-10 15:40:16 +0100116/**
117 * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack.
118 */
119public class NotificationStackScrollLayout extends ViewGroup
Jorim Jaggibe565df2014-04-28 17:51:23 +0200120 implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter,
Mady Mellor4b80b102016-01-22 08:03:58 -0800121 ExpandableView.OnHeightChangedListener, NotificationGroupManager.OnGroupChangeListener,
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900122 NotificationMenuRowPlugin.OnMenuEventListener, VisibilityLocationProvider,
123 NotificationListContainer {
Selim Cinek67b22602014-03-10 15:40:16 +0100124
Selim Cinekd35c2792016-01-21 13:20:57 -0800125 public static final float BACKGROUND_ALPHA_DIMMED = 0.7f;
Selim Cinek3776fe02016-02-04 13:32:43 -0800126 private static final String TAG = "StackScroller";
Selim Cinek67b22602014-03-10 15:40:16 +0100127 private static final boolean DEBUG = false;
Selim Cinek1408eb52014-06-02 14:45:38 +0200128 private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f;
129 private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f;
Jorim Jaggi47c85a32014-06-05 17:25:40 +0200130 private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f;
Selim Cinek67b22602014-03-10 15:40:16 +0100131 /**
132 * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}.
133 */
Lucas Dupind285cf02018-01-18 09:18:23 -0800134 private static final int INVALID_POINTER = -1;
Selim Cinek67b22602014-03-10 15:40:16 +0100135
Selim Cinek1408eb52014-06-02 14:45:38 +0200136 private ExpandHelper mExpandHelper;
Selim Cinek33223572016-02-19 19:32:22 -0800137 private NotificationSwipeHelper mSwipeHelper;
Selim Cinek343e6e22014-04-11 21:23:30 +0200138 private boolean mSwipingInProgress;
Selim Cinek67b22602014-03-10 15:40:16 +0100139 private int mCurrentStackHeight = Integer.MAX_VALUE;
Selim Cinekd35c2792016-01-21 13:20:57 -0800140 private final Paint mBackgroundPaint = new Paint();
Adrian Roosf0b4f962017-05-25 11:53:11 -0700141 private final boolean mShouldDrawNotificationBackground;
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +0100142
Selim Cinekbc243a92016-09-27 16:35:13 -0700143 private float mExpandedHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100144 private int mOwnScrollY;
145 private int mMaxLayoutHeight;
146
147 private VelocityTracker mVelocityTracker;
148 private OverScroller mScroller;
Ricky Waicd35def2016-05-03 11:07:07 +0100149 private Runnable mFinishScrollingCallback;
Selim Cinek67b22602014-03-10 15:40:16 +0100150 private int mTouchSlop;
151 private int mMinimumVelocity;
152 private int mMaximumVelocity;
Selim Cinek67b22602014-03-10 15:40:16 +0100153 private int mOverflingDistance;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200154 private float mMaxOverScroll;
Selim Cinek67b22602014-03-10 15:40:16 +0100155 private boolean mIsBeingDragged;
156 private int mLastMotionY;
Selim Cinek1408eb52014-06-02 14:45:38 +0200157 private int mDownX;
Dong-wan Kimb9266662016-09-21 13:08:30 -0700158 private int mActivePointerId = INVALID_POINTER;
Selim Cinek3a9c10a2014-10-28 14:21:10 +0100159 private boolean mTouchIsClick;
160 private float mInitialTouchX;
161 private float mInitialTouchY;
Selim Cinek67b22602014-03-10 15:40:16 +0100162
Selim Cinek67b22602014-03-10 15:40:16 +0100163 private Paint mDebugPaint;
Selim Cinek67b22602014-03-10 15:40:16 +0100164 private int mContentHeight;
Lucas Dupin60661a62018-04-12 10:50:13 -0700165 private int mIntrinsicContentHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100166 private int mCollapsedSize;
Selim Cinek67b22602014-03-10 15:40:16 +0100167 private int mPaddingBetweenElements;
Selim Cinek61633a82016-01-25 15:54:10 -0800168 private int mIncreasedPaddingBetweenElements;
shawnlin8e4e92c2018-04-12 18:47:24 +0800169 private int mMaxTopPadding;
Lucas Dupind285cf02018-01-18 09:18:23 -0800170 private int mRegularTopPadding;
171 private int mDarkTopPadding;
172 // Current padding, will be either mRegularTopPadding or mDarkTopPadding
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200173 private int mTopPadding;
Lucas Dupind285cf02018-01-18 09:18:23 -0800174 // Distance between AOD separator and shelf
175 private int mDarkSeparatorPadding;
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700176 private int mBottomMargin;
Adrian Roos5153d4a2016-03-22 10:01:56 -0700177 private int mBottomInset = 0;
shawnlin8e4e92c2018-04-12 18:47:24 +0800178 private float mQsExpansionFraction;
Selim Cinek67b22602014-03-10 15:40:16 +0100179
180 /**
181 * The algorithm which calculates the properties for our children
182 */
Muyuan Li87798022016-04-07 17:51:25 -0700183 protected final StackScrollAlgorithm mStackScrollAlgorithm;
Selim Cinek67b22602014-03-10 15:40:16 +0100184
185 /**
186 * The current State this Layout is in
187 */
Selim Cinek572bbd42014-04-25 16:43:27 +0200188 private StackScrollState mCurrentStackScrollState = new StackScrollState(this);
Selim Cinek281c2022016-10-13 19:14:43 -0700189 private final AmbientState mAmbientState;
Selim Cinekb5605e52015-02-20 18:21:41 +0100190 private NotificationGroupManager mGroupManager;
Selim Cinek3776fe02016-02-04 13:32:43 -0800191 private HashSet<View> mChildrenToAddAnimated = new HashSet<>();
Selim Cineka59ecc32015-04-07 10:51:49 -0700192 private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>();
193 private ArrayList<View> mChildrenToRemoveAnimated = new ArrayList<>();
194 private ArrayList<View> mSnappedBackChildren = new ArrayList<>();
195 private ArrayList<View> mDragAnimPendingChildren = new ArrayList<>();
196 private ArrayList<View> mChildrenChangingPositions = new ArrayList<>();
Jorim Jaggiff9c9c42014-08-01 05:36:22 +0200197 private HashSet<View> mFromMoreCardAdditions = new HashSet<>();
Selim Cineka59ecc32015-04-07 10:51:49 -0700198 private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>();
199 private ArrayList<View> mSwipedOutViews = new ArrayList<>();
Selim Cinek572bbd42014-04-25 16:43:27 +0200200 private final StackStateAnimator mStateAnimator = new StackStateAnimator(this);
Jorim Jaggi75c95042014-05-16 19:09:59 +0200201 private boolean mAnimationsEnabled;
Selim Cinek159ffdb2014-06-04 22:24:18 +0200202 private boolean mChangePositionInProgress;
Selim Cinekef5127e2015-12-21 16:55:58 -0800203 private boolean mChildTransferInProgress;
Selim Cinek1685e632014-04-08 02:27:49 +0200204
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200205 /**
206 * The raw amount of the overScroll on the top, which is not rubber-banded.
207 */
208 private float mOverScrolledTopPixels;
209
210 /**
211 * The raw amount of the overScroll on the bottom, which is not rubber-banded.
212 */
213 private float mOverScrolledBottomPixels;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900214 private NotificationLogger.OnChildLocationsChangedListener mListener;
Jorim Jaggi290600a2014-05-30 17:02:20 +0200215 private OnOverscrollTopChangedListener mOverscrollTopChangedListener;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200216 private ExpandableView.OnHeightChangedListener mOnHeightChangedListener;
Selim Cinek3a9c10a2014-10-28 14:21:10 +0100217 private OnEmptySpaceClickListener mOnEmptySpaceClickListener;
Jorim Jaggi0dd68812014-05-01 19:17:37 +0200218 private boolean mNeedsAnimation;
219 private boolean mTopPaddingNeedsAnimation;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200220 private boolean mDimmedNeedsAnimation;
Jorim Jaggiae441282014-08-01 02:45:18 +0200221 private boolean mHideSensitiveNeedsAnimation;
John Spurlockbf370992014-06-17 13:58:31 -0400222 private boolean mDarkNeedsAnimation;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100223 private int mDarkAnimationOriginIndex;
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200224 private boolean mActivateNeedsAnimation;
Jorim Jaggi60d07c52014-07-31 15:38:21 +0200225 private boolean mGoToFullShadeNeedsAnimation;
Selim Cinek572bbd42014-04-25 16:43:27 +0200226 private boolean mIsExpanded = true;
Selim Cinek1f553cf2014-05-02 12:01:36 +0200227 private boolean mChildrenUpdateRequested;
Selim Cinekc27437b2014-05-14 10:23:33 +0200228 private boolean mIsExpansionChanging;
Jorim Jaggie4b840d2015-06-30 16:19:17 -0700229 private boolean mPanelTracking;
Selim Cinek1408eb52014-06-02 14:45:38 +0200230 private boolean mExpandingNotification;
231 private boolean mExpandedInThisMotion;
shawnlin8e4e92c2018-04-12 18:47:24 +0800232 private boolean mShouldShowShelfOnly;
Muyuan Li84b45612016-06-01 11:05:08 -0700233 protected boolean mScrollingEnabled;
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400234 protected FooterView mFooterView;
Muyuan Lidd9ae752016-05-13 16:45:43 -0700235 protected EmptyShadeView mEmptyShadeView;
Dan Sandlereceda3d2014-07-21 15:35:01 -0400236 private boolean mDismissAllInProgress;
Anthony Chen7acbb772017-04-07 16:45:25 -0700237 private boolean mFadeNotificationsOnDismiss;
Selim Cinek1408eb52014-06-02 14:45:38 +0200238
239 /**
240 * Was the scroller scrolled to the top when the down motion was observed?
241 */
242 private boolean mScrolledToTopOnFirstDown;
Selim Cinek1408eb52014-06-02 14:45:38 +0200243 /**
244 * The minimal amount of over scroll which is needed in order to switch to the quick settings
245 * when over scrolling on a expanded card.
246 */
247 private float mMinTopOverScrollToEscape;
248 private int mIntrinsicPadding;
Selim Cinekd2281152015-04-10 14:37:46 -0700249 private float mStackTranslation;
Jorim Jaggi30c305c2014-07-01 23:34:41 +0200250 private float mTopPaddingOverflow;
Selim Cinek1408eb52014-06-02 14:45:38 +0200251 private boolean mDontReportNextOverScroll;
Adrian Roos5153d4a2016-03-22 10:01:56 -0700252 private boolean mDontClampNextScroll;
Selim Cineka5e211b2014-08-11 17:35:48 +0200253 private boolean mNeedViewResizeAnimation;
Selim Cinekb5605e52015-02-20 18:21:41 +0100254 private View mExpandedGroupView;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700255 private boolean mEverythingNeedsAnimation;
Selim Cineka59ecc32015-04-07 10:51:49 -0700256
Selim Cinek1408eb52014-06-02 14:45:38 +0200257 /**
258 * The maximum scrollPosition which we are allowed to reach when a notification was expanded.
259 * This is needed to avoid scrolling too far after the notification was collapsed in the same
260 * motion.
261 */
262 private int mMaxScrollAfterExpand;
Geoffrey Pitsch409db272017-08-28 14:51:52 +0000263 private ExpandableNotificationRow.LongPressListener mLongPressListener;
Mady Mellor4b80b102016-01-22 08:03:58 -0800264
Mady Mellor95d743c2017-01-10 12:05:27 -0800265 private NotificationMenuRowPlugin mCurrMenuRow;
Mady Mellor4b80b102016-01-22 08:03:58 -0800266 private View mTranslatingParentView;
Mady Mellor95d743c2017-01-10 12:05:27 -0800267 private View mMenuExposedView;
Mady Mellorc2dbe492017-03-30 13:22:03 -0700268 boolean mCheckForLeavebehind;
Selim Cinek1408eb52014-06-02 14:45:38 +0200269
270 /**
271 * Should in this touch motion only be scrolling allowed? It's true when the scroller was
272 * animating.
273 */
274 private boolean mOnlyScrollingInThisMotion;
Adrian Roosfa139752016-04-27 09:59:08 -0700275 private boolean mDisallowDismissInThisMotion;
Selim Cineka59ecc32015-04-07 10:51:49 -0700276 private boolean mDisallowScrollingInThisMotion;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700277 private long mGoToFullShadeDelay;
Selim Cinek1f553cf2014-05-02 12:01:36 +0200278 private ViewTreeObserver.OnPreDrawListener mChildrenUpdater
Selim Cinek572bbd42014-04-25 16:43:27 +0200279 = new ViewTreeObserver.OnPreDrawListener() {
280 @Override
281 public boolean onPreDraw() {
Adrian Roos181385c2016-05-05 17:45:44 -0400282 updateForcedScroll();
Selim Cinek1f553cf2014-05-02 12:01:36 +0200283 updateChildren();
284 mChildrenUpdateRequested = false;
285 getViewTreeObserver().removeOnPreDrawListener(this);
Selim Cinek572bbd42014-04-25 16:43:27 +0200286 return true;
287 }
288 };
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500289 private StatusBar mStatusBar;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +0100290 private int[] mTempInt2 = new int[2];
Selim Cinekb5605e52015-02-20 18:21:41 +0100291 private boolean mGenerateChildOrderChangedEvent;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700292 private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>();
Selim Cinek9dd0d042018-05-14 18:12:42 -0700293 private HashSet<ExpandableView> mClearTransientViewsWhenFinished = new HashSet<>();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700294 private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations
295 = new HashSet<>();
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900296 private HeadsUpManagerPhone mHeadsUpManager;
Selim Cinek29aab962018-02-27 17:05:45 -0800297 private NotificationRoundnessManager mRoundnessManager = new NotificationRoundnessManager();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700298 private boolean mTrackingHeadsUp;
Selim Cinekaac93252015-04-14 20:04:12 -0700299 private ScrimController mScrimController;
Selim Cinekbbc580b2015-06-03 14:11:03 +0200300 private boolean mForceNoOverlappingRendering;
Selim Cineke0890e52015-06-17 11:17:08 -0700301 private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700302 private FalsingManager mFalsingManager;
Selim Cinek6811d722016-01-19 17:53:12 -0800303 private boolean mAnimationRunning;
Selim Cinekc383fd02016-10-21 15:31:26 -0700304 private ViewTreeObserver.OnPreDrawListener mRunningAnimationUpdater
Selim Cinek6811d722016-01-19 17:53:12 -0800305 = new ViewTreeObserver.OnPreDrawListener() {
306 @Override
307 public boolean onPreDraw() {
Selim Cinekc383fd02016-10-21 15:31:26 -0700308 onPreDrawDuringAnimation();
Selim Cinek6811d722016-01-19 17:53:12 -0800309 return true;
310 }
311 };
312 private Rect mBackgroundBounds = new Rect();
Selim Cinek614576e2016-01-20 10:54:09 -0800313 private Rect mStartAnimationRect = new Rect();
314 private Rect mEndAnimationRect = new Rect();
Selim Cinekd35c2792016-01-21 13:20:57 -0800315 private Rect mCurrentBounds = new Rect(-1, -1, -1, -1);
Selim Cinek614576e2016-01-20 10:54:09 -0800316 private boolean mAnimateNextBackgroundBottom;
317 private boolean mAnimateNextBackgroundTop;
318 private ObjectAnimator mBottomAnimator = null;
319 private ObjectAnimator mTopAnimator = null;
320 private ActivatableNotificationView mFirstVisibleBackgroundChild = null;
321 private ActivatableNotificationView mLastVisibleBackgroundChild = null;
Selim Cinekd35c2792016-01-21 13:20:57 -0800322 private int mBgColor;
323 private float mDimAmount;
324 private ValueAnimator mDimAnimator;
Selim Cinek33223572016-02-19 19:32:22 -0800325 private ArrayList<ExpandableView> mTmpSortedChildren = new ArrayList<>();
Selim Cinekd35c2792016-01-21 13:20:57 -0800326 private Animator.AnimatorListener mDimEndListener = new AnimatorListenerAdapter() {
327 @Override
328 public void onAnimationEnd(Animator animation) {
329 mDimAnimator = null;
330 }
331 };
332 private ValueAnimator.AnimatorUpdateListener mDimUpdateListener
333 = new ValueAnimator.AnimatorUpdateListener() {
334
335 @Override
336 public void onAnimationUpdate(ValueAnimator animation) {
337 setDimAmount((Float) animation.getAnimatedValue());
338 }
339 };
Muyuan Li4fe4a402016-03-30 16:50:11 -0700340 protected ViewGroup mQsContainer;
Selim Cinek33223572016-02-19 19:32:22 -0800341 private boolean mContinuousShadowUpdate;
342 private ViewTreeObserver.OnPreDrawListener mShadowUpdater
343 = new ViewTreeObserver.OnPreDrawListener() {
344
345 @Override
346 public boolean onPreDraw() {
347 updateViewShadows();
348 return true;
349 }
350 };
351 private Comparator<ExpandableView> mViewPositionComparator = new Comparator<ExpandableView>() {
352 @Override
353 public int compare(ExpandableView view, ExpandableView otherView) {
354 float endY = view.getTranslationY() + view.getActualHeight();
355 float otherEndY = otherView.getTranslationY() + otherView.getActualHeight();
356 if (endY < otherEndY) {
357 return -1;
358 } else if (endY > otherEndY) {
359 return 1;
360 } else {
361 // The two notifications end at the same location
362 return 0;
363 }
364 }
365 };
Selim Cinek25503252016-03-03 15:31:43 -0800366 private PorterDuffXfermode mSrcMode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900367 private boolean mPulsing;
Selim Cinek31d37b92016-04-26 09:56:42 -0700368 private boolean mDrawBackgroundAsSrc;
Selim Cinek07304f5222016-05-19 18:31:36 -0700369 private boolean mFadingOut;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800370 private boolean mParentNotFullyVisible;
Selim Cinek1b2a05e2016-04-28 14:20:39 -0700371 private boolean mGroupExpandedForMeasure;
Selim Cinekc22fff62016-05-20 12:44:30 -0700372 private boolean mScrollable;
Adrian Roos181385c2016-05-05 17:45:44 -0400373 private View mForcedScroll;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700374 private View mNeedingPulseAnimation;
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200375
376 /**
377 * @see #setDarkAmount(float, float)
378 */
379 private float mInterpolatedDarkAmount = 0f;
380
381 /**
382 * @see #setDarkAmount(float, float)
383 */
384 private float mLinearDarkAmount = 0f;
Lucas Dupin439bd442018-06-12 15:05:28 -0700385
386 /**
387 * How fast the background scales in the X direction as a factor of the Y expansion.
388 */
389 private float mBackgroundXFactor = 1f;
Selim Cinek972123d2016-05-03 14:25:58 -0700390
Lucas Dupine17ce522017-07-17 15:45:06 -0700391 private boolean mUsingLightTheme;
Selim Cinekbc243a92016-09-27 16:35:13 -0700392 private boolean mQsExpanded;
Selim Cinekef406062016-09-29 17:33:13 -0700393 private boolean mForwardScrollable;
394 private boolean mBackwardScrollable;
Selim Cinek281c2022016-10-13 19:14:43 -0700395 private NotificationShelf mShelf;
Selim Cinekad7fac02016-10-18 17:09:15 -0700396 private int mMaxDisplayedNotifications = -1;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800397 private int mStatusBarHeight;
Selim Cinek51d21972017-07-19 17:39:20 -0700398 private int mMinInteractionHeight;
Selim Cinek48ff9b42016-11-09 19:31:51 -0800399 private boolean mNoAmbient;
400 private final Rect mClipRect = new Rect();
401 private boolean mIsClipped;
Selim Cinekcafa87f2016-10-26 17:00:17 -0700402 private Rect mRequestedClipBounds;
403 private boolean mInHeadsUpPinnedMode;
404 private boolean mHeadsUpAnimatingAway;
Selim Cinek355652a2016-12-07 13:32:12 -0800405 private int mStatusBarState;
Selim Cinekfb6ee6d2016-12-29 16:49:26 +0100406 private int mCachedBackgroundColor;
Selim Cinek5cf1d052017-06-01 17:36:46 -0700407 private boolean mHeadsUpGoingAwayAnimationsAllowed = true;
Selim Cinek9212de82017-02-06 16:04:28 -0800408 private Runnable mAnimateScroll = this::animateScroll;
Selim Cinek0fe07392017-11-09 13:26:34 -0800409 private int mCornerRadius;
Selim Cinek515b2032017-11-15 10:20:19 -0800410 private int mSidePaddings;
Lucas Dupind285cf02018-01-18 09:18:23 -0800411 private final int mSeparatorWidth;
412 private final int mSeparatorThickness;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800413 private final Rect mBackgroundAnimationRect = new Rect();
Lucas Dupin0cd882f2018-01-30 12:19:49 -0800414 private int mAntiBurnInOffsetX;
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800415 private ArrayList<BiConsumer<Float, Float>> mExpandedHeightListeners = new ArrayList<>();
416 private int mHeadsUpInset;
Selim Cinekf0c79e12018-05-14 17:17:31 -0700417 private HeadsUpAppearanceController mHeadsUpAppearanceController;
Selim Cinek9bfc7a52018-06-11 16:09:00 -0700418 private NotificationIconAreaController mIconAreaController;
Bill Lin278e7d62018-06-13 18:07:15 +0800419 private float mVerticalPanelTranslation;
Selim Cinek67b22602014-03-10 15:40:16 +0100420
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200421 private Interpolator mDarkXInterpolator = Interpolators.FAST_OUT_SLOW_IN;
422
Selim Cinek67b22602014-03-10 15:40:16 +0100423 public NotificationStackScrollLayout(Context context) {
424 this(context, null);
425 }
426
427 public NotificationStackScrollLayout(Context context, AttributeSet attrs) {
428 this(context, attrs, 0);
429 }
430
431 public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) {
432 this(context, attrs, defStyleAttr, 0);
433 }
434
435 public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr,
436 int defStyleRes) {
437 super(context, attrs, defStyleAttr, defStyleRes);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800438 Resources res = getResources();
439
Selim Cinek281c2022016-10-13 19:14:43 -0700440 mAmbientState = new AmbientState(context);
Selim Cinekd35c2792016-01-21 13:20:57 -0800441 mBgColor = context.getColor(R.color.notification_shade_background_color);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800442 int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height);
443 int maxHeight = res.getDimensionPixelSize(R.dimen.notification_max_height);
Selim Cinek1cf41c12014-08-12 20:06:19 +0200444 mExpandHelper = new ExpandHelper(getContext(), this,
445 minHeight, maxHeight);
446 mExpandHelper.setEventSource(this);
447 mExpandHelper.setScrollAdapter(this);
Mady Mellor4b80b102016-01-22 08:03:58 -0800448 mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, this, getContext());
Muyuan Li333a4fc2016-04-16 17:13:46 -0700449 mStackScrollAlgorithm = createStackScrollAlgorithm(context);
Selim Cinek67b22602014-03-10 15:40:16 +0100450 initView(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800451 mFalsingManager = FalsingManager.getInstance(context);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800452 mShouldDrawNotificationBackground =
453 res.getBoolean(R.bool.config_drawNotificationBackground);
Anthony Chen7acbb772017-04-07 16:45:25 -0700454 mFadeNotificationsOnDismiss =
455 res.getBoolean(R.bool.config_fadeNotificationsOnDismiss);
Lucas Dupind285cf02018-01-18 09:18:23 -0800456 mSeparatorWidth = res.getDimensionPixelSize(R.dimen.widget_separator_width);
457 mSeparatorThickness = res.getDimensionPixelSize(R.dimen.widget_separator_thickness);
458 mDarkSeparatorPadding = res.getDimensionPixelSize(R.dimen.widget_bottom_separator_padding);
Selim Cinek29aab962018-02-27 17:05:45 -0800459 mRoundnessManager.setAnimatedChildren(mChildrenToAddAnimated);
460 mRoundnessManager.setOnRoundingChangedCallback(this::invalidate);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800461 addOnExpandedHeightListener(mRoundnessManager::setExpanded);
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800462
Rohan Shah524cf7b2018-03-15 14:40:02 -0700463 // Blocking helper manager wants to know the expanded state, update as well.
464 NotificationBlockingHelperManager blockingHelperManager =
465 Dependency.get(NotificationBlockingHelperManager.class);
466 addOnExpandedHeightListener((height, unused) -> {
467 blockingHelperManager.setNotificationShadeExpanded(height);
468 });
469
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800470 updateWillNotDraw();
Lucas Dupind285cf02018-01-18 09:18:23 -0800471 mBackgroundPaint.setAntiAlias(true);
Selim Cinek67b22602014-03-10 15:40:16 +0100472 if (DEBUG) {
Selim Cinek67b22602014-03-10 15:40:16 +0100473 mDebugPaint = new Paint();
474 mDebugPaint.setColor(0xffff0000);
475 mDebugPaint.setStrokeWidth(2);
476 mDebugPaint.setStyle(Paint.Style.STROKE);
477 }
478 }
479
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900480 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -0800481 public NotificationSwipeActionHelper getSwipeActionHelper() {
482 return mSwipeHelper;
483 }
484
Selim Cinek67b22602014-03-10 15:40:16 +0100485 @Override
Mady Mellor43c2cd12016-12-12 21:05:13 -0800486 public void onMenuClicked(View view, int x, int y, MenuItem item) {
487 if (mLongPressListener == null) {
488 return;
489 }
490 if (view instanceof ExpandableNotificationRow) {
491 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Mady Mellora41587b2016-02-11 18:43:06 -0800492 MetricsLogger.action(mContext, MetricsEvent.ACTION_TOUCH_GEAR,
493 row.getStatusBarNotification().getPackageName());
Mady Mellor4b80b102016-01-22 08:03:58 -0800494 }
Mady Mellor43c2cd12016-12-12 21:05:13 -0800495 mLongPressListener.onLongPress(view, x, y, item);
Mady Mellor4b80b102016-01-22 08:03:58 -0800496 }
497
498 @Override
Mady Mellor43c2cd12016-12-12 21:05:13 -0800499 public void onMenuReset(View row) {
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700500 if (mTranslatingParentView != null && row == mTranslatingParentView) {
Mady Mellor95d743c2017-01-10 12:05:27 -0800501 mMenuExposedView = null;
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700502 mTranslatingParentView = null;
503 }
Mady Mellor3a5e8dd2016-03-12 00:13:23 +0000504 }
505
506 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -0800507 public void onMenuShown(View row) {
508 mMenuExposedView = mTranslatingParentView;
509 if (row instanceof ExpandableNotificationRow) {
510 MetricsLogger.action(mContext, MetricsEvent.ACTION_REVEAL_GEAR,
511 ((ExpandableNotificationRow) row).getStatusBarNotification()
512 .getPackageName());
513 }
514 mSwipeHelper.onMenuShown(row);
515 }
516
Selim Cinek67b22602014-03-10 15:40:16 +0100517 protected void onDraw(Canvas canvas) {
Lucas Dupind285cf02018-01-18 09:18:23 -0800518 if (mShouldDrawNotificationBackground
519 && (mCurrentBounds.top < mCurrentBounds.bottom || mAmbientState.isDark())) {
520 drawBackground(canvas);
Selim Cinekd381bc32016-08-15 12:40:57 -0700521 }
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800522
Selim Cinek67b22602014-03-10 15:40:16 +0100523 if (DEBUG) {
Selim Cinek816c8e42015-11-19 12:00:45 -0800524 int y = mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +0100525 canvas.drawLine(0, y, getWidth(), y, mDebugPaint);
Mady Mellor43c2cd12016-12-12 21:05:13 -0800526 y = getLayoutHeight();
Selim Cinek67b22602014-03-10 15:40:16 +0100527 canvas.drawLine(0, y, getWidth(), y, mDebugPaint);
Jorim Jaggi1d480692014-05-20 19:41:58 +0200528 y = getHeight() - getEmptyBottomMargin();
529 canvas.drawLine(0, y, getWidth(), y, mDebugPaint);
Selim Cinek67b22602014-03-10 15:40:16 +0100530 }
531 }
532
Lucas Dupind285cf02018-01-18 09:18:23 -0800533 private void drawBackground(Canvas canvas) {
534 final int lockScreenLeft = mSidePaddings;
535 final int lockScreenRight = getWidth() - mSidePaddings;
536 final int lockScreenTop = mCurrentBounds.top;
537 final int lockScreenBottom = mCurrentBounds.bottom;
Selim Cinek9bfc7a52018-06-11 16:09:00 -0700538 int separatorWidth = 0;
539 int separatorThickness = 0;
540 if (mIconAreaController.hasShelfIconsWhenFullyDark()) {
541 separatorThickness = mSeparatorThickness;
542 separatorWidth = mSeparatorWidth;
543 }
544 final int darkLeft = getWidth() / 2 - separatorWidth / 2;
545 final int darkRight = darkLeft + separatorWidth;
546 final int darkTop = (int) (mRegularTopPadding + separatorThickness / 2f);
547 final int darkBottom = darkTop + separatorThickness;
Lucas Dupind285cf02018-01-18 09:18:23 -0800548
Lucas Dupin6bf7b642018-01-22 18:56:24 -0800549 if (mAmbientState.hasPulsingNotifications()) {
Lucas Dupin16cfe452018-02-08 13:14:50 -0800550 // No divider, we have a notification icon instead
551 } else if (mAmbientState.isFullyDark()) {
Lucas Dupind285cf02018-01-18 09:18:23 -0800552 // Only draw divider on AOD if we actually have notifications
553 if (mFirstVisibleBackgroundChild != null) {
554 canvas.drawRect(darkLeft, darkTop, darkRight, darkBottom, mBackgroundPaint);
555 }
Lucas Dupind285cf02018-01-18 09:18:23 -0800556 } else {
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200557 float yProgress = 1 - mInterpolatedDarkAmount;
558 float xProgress = mDarkXInterpolator.getInterpolation(
559 (1 - mLinearDarkAmount) * mBackgroundXFactor);
Lucas Dupin60661a62018-04-12 10:50:13 -0700560
Lucas Dupin16cfe452018-02-08 13:14:50 -0800561 mBackgroundAnimationRect.set(
Lucas Dupin60661a62018-04-12 10:50:13 -0700562 (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress),
563 (int) MathUtils.lerp(darkTop, lockScreenTop, yProgress),
564 (int) MathUtils.lerp(darkRight, lockScreenRight, xProgress),
565 (int) MathUtils.lerp(darkBottom, lockScreenBottom, yProgress));
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200566
Lucas Dupin16cfe452018-02-08 13:14:50 -0800567 if (!mAmbientState.isDark() || mFirstVisibleBackgroundChild != null) {
568 canvas.drawRoundRect(mBackgroundAnimationRect.left, mBackgroundAnimationRect.top,
569 mBackgroundAnimationRect.right, mBackgroundAnimationRect.bottom,
570 mCornerRadius, mCornerRadius, mBackgroundPaint);
571 }
Lucas Dupind285cf02018-01-18 09:18:23 -0800572 }
Lucas Dupin16cfe452018-02-08 13:14:50 -0800573 updateClipping();
Lucas Dupind285cf02018-01-18 09:18:23 -0800574 }
575
Selim Cinekd35c2792016-01-21 13:20:57 -0800576 private void updateBackgroundDimming() {
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800577 // No need to update the background color if it's not being drawn.
578 if (!mShouldDrawNotificationBackground) {
579 return;
580 }
581
Lucas Dupinb561eda2018-04-09 17:25:04 -0700582 float alpha =
583 BACKGROUND_ALPHA_DIMMED + (1 - BACKGROUND_ALPHA_DIMMED) * (1.0f - mDimAmount);
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200584 alpha *= 1f - mInterpolatedDarkAmount;
Lucas Dupinb561eda2018-04-09 17:25:04 -0700585 // We need to manually blend in the background color.
586 int scrimColor = mScrimController.getBackgroundColor();
587 int awakeColor = ColorUtils.blendARGB(scrimColor, mBgColor, alpha);
588
589 // Interpolate between semi-transparent notification panel background color
590 // and white AOD separator.
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200591 float colorInterpolation = Interpolators.DECELERATE_QUINT.getInterpolation(
592 mInterpolatedDarkAmount);
Lucas Dupinb561eda2018-04-09 17:25:04 -0700593 int color = ColorUtils.blendARGB(awakeColor, Color.WHITE, colorInterpolation);
Lucas Dupind285cf02018-01-18 09:18:23 -0800594
Selim Cinekfb6ee6d2016-12-29 16:49:26 +0100595 if (mCachedBackgroundColor != color) {
596 mCachedBackgroundColor = color;
597 mBackgroundPaint.setColor(color);
598 invalidate();
599 }
Selim Cinekd35c2792016-01-21 13:20:57 -0800600 }
601
Selim Cinek67b22602014-03-10 15:40:16 +0100602 private void initView(Context context) {
603 mScroller = new OverScroller(getContext());
Selim Cinek67b22602014-03-10 15:40:16 +0100604 setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200605 setClipChildren(false);
Selim Cinek67b22602014-03-10 15:40:16 +0100606 final ViewConfiguration configuration = ViewConfiguration.get(context);
607 mTouchSlop = configuration.getScaledTouchSlop();
608 mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
609 mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
Selim Cinek67b22602014-03-10 15:40:16 +0100610 mOverflingDistance = configuration.getScaledOverflingDistance();
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700611
612 Resources res = context.getResources();
613 mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height);
Selim Cinekaf0dc312015-12-15 17:01:44 -0800614 mStackScrollAlgorithm.initView(context);
Selim Cinek281c2022016-10-13 19:14:43 -0700615 mAmbientState.reload(context);
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700616 mPaddingBetweenElements = Math.max(1,
617 res.getDimensionPixelSize(R.dimen.notification_divider_height));
618 mIncreasedPaddingBetweenElements =
619 res.getDimensionPixelSize(R.dimen.notification_divider_height_increased);
620 mMinTopOverScrollToEscape = res.getDimensionPixelSize(
Selim Cinek1408eb52014-06-02 14:45:38 +0200621 R.dimen.min_top_overscroll_to_qs);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800622 mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height);
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700623 mBottomMargin = res.getDimensionPixelSize(R.dimen.notification_panel_margin_bottom);
Selim Cinekb95fd182017-12-21 13:03:32 -0800624 mSidePaddings = res.getDimensionPixelSize(R.dimen.notification_side_paddings);
Selim Cinek51d21972017-07-19 17:39:20 -0700625 mMinInteractionHeight = res.getDimensionPixelSize(
626 R.dimen.notification_min_interaction_height);
Selim Cinek0fe07392017-11-09 13:26:34 -0800627 mCornerRadius = res.getDimensionPixelSize(
628 Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius));
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800629 mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize(
630 R.dimen.heads_up_status_bar_padding);
Selim Cineka5eaa602014-05-12 21:27:47 +0200631 }
632
Selim Cinek25503252016-03-03 15:31:43 -0800633 public void setDrawBackgroundAsSrc(boolean asSrc) {
Selim Cinek31d37b92016-04-26 09:56:42 -0700634 mDrawBackgroundAsSrc = asSrc;
635 updateSrcDrawing();
636 }
637
638 private void updateSrcDrawing() {
Anthony Chen3cb3ad92016-12-01 10:58:47 -0800639 if (!mShouldDrawNotificationBackground) {
640 return;
641 }
642
Selim Cinek48ff9b42016-11-09 19:31:51 -0800643 mBackgroundPaint.setXfermode(mDrawBackgroundAsSrc && !mFadingOut && !mParentNotFullyVisible
Selim Cinek07304f5222016-05-19 18:31:36 -0700644 ? mSrcMode : null);
Selim Cinek25503252016-03-03 15:31:43 -0800645 invalidate();
646 }
647
Selim Cinekaef92ef2014-06-06 18:06:04 +0200648 private void notifyHeightChangeListener(ExpandableView view) {
Lucas Dupin60661a62018-04-12 10:50:13 -0700649 notifyHeightChangeListener(view, false /* needsAnimation */);
650 }
651
652 private void notifyHeightChangeListener(ExpandableView view, boolean needsAnimation) {
Selim Cinekaef92ef2014-06-06 18:06:04 +0200653 if (mOnHeightChangedListener != null) {
Lucas Dupin60661a62018-04-12 10:50:13 -0700654 mOnHeightChangedListener.onHeightChanged(view, needsAnimation);
Selim Cinekaef92ef2014-06-06 18:06:04 +0200655 }
Selim Cinek67b22602014-03-10 15:40:16 +0100656 }
657
658 @Override
659 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
660 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Selim Cinekb95fd182017-12-21 13:03:32 -0800661
662 int width = MeasureSpec.getSize(widthMeasureSpec);
663 int childWidthSpec = MeasureSpec.makeMeasureSpec(width - mSidePaddings * 2,
664 MeasureSpec.getMode(widthMeasureSpec));
Selim Cinekfa760d42016-05-10 15:50:53 -0400665 // We need to measure all children even the GONE ones, such that the heights are calculated
666 // correctly as they are used to calculate how many we can fit on the screen.
667 final int size = getChildCount();
668 for (int i = 0; i < size; i++) {
Selim Cinekb95fd182017-12-21 13:03:32 -0800669 measureChild(getChildAt(i), childWidthSpec, heightMeasureSpec);
Selim Cinekfa760d42016-05-10 15:50:53 -0400670 }
Selim Cinek67b22602014-03-10 15:40:16 +0100671 }
672
673 @Override
674 protected void onLayout(boolean changed, int l, int t, int r, int b) {
Selim Cinek67b22602014-03-10 15:40:16 +0100675 // we layout all our children centered on the top
676 float centerX = getWidth() / 2.0f;
677 for (int i = 0; i < getChildCount(); i++) {
678 View child = getChildAt(i);
Selim Cinekfa760d42016-05-10 15:50:53 -0400679 // We need to layout all children even the GONE ones, such that the heights are
680 // calculated correctly as they are used to calculate how many we can fit on the screen
Selim Cinek67b22602014-03-10 15:40:16 +0100681 float width = child.getMeasuredWidth();
682 float height = child.getMeasuredHeight();
Selim Cinek67b22602014-03-10 15:40:16 +0100683 child.layout((int) (centerX - width / 2.0f),
684 0,
685 (int) (centerX + width / 2.0f),
686 (int) height);
Selim Cinek67b22602014-03-10 15:40:16 +0100687 }
Jorim Jaggi1d480692014-05-20 19:41:58 +0200688 setMaxLayoutHeight(getHeight());
Selim Cinek67b22602014-03-10 15:40:16 +0100689 updateContentHeight();
Selim Cinekf7a14c02014-07-07 14:01:46 +0200690 clampScrollPosition();
Selim Cinek319bdc42014-05-01 23:01:58 +0200691 requestChildrenUpdate();
Selim Cinek614576e2016-01-20 10:54:09 -0800692 updateFirstAndLastBackgroundViews();
Selim Cinekbc243a92016-09-27 16:35:13 -0700693 updateAlgorithmLayoutMinHeight();
Selim Cinek67b22602014-03-10 15:40:16 +0100694 }
695
Selim Cinek5bc852a2015-12-21 12:19:09 -0800696 private void requestAnimationOnViewResize(ExpandableNotificationRow row) {
697 if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) {
Selim Cineka5e211b2014-08-11 17:35:48 +0200698 mNeedViewResizeAnimation = true;
699 mNeedsAnimation = true;
700 }
Selim Cineka5e211b2014-08-11 17:35:48 +0200701 }
702
Selim Cinekdb167372016-11-17 15:41:17 -0800703 public void updateSpeedBumpIndex(int newIndex, boolean noAmbient) {
704 mAmbientState.setSpeedBumpIndex(newIndex);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800705 mNoAmbient = noAmbient;
Selim Cinekc27437b2014-05-14 10:23:33 +0200706 }
707
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900708 @Override
709 public void setChildLocationsChangedListener(
710 NotificationLogger.OnChildLocationsChangedListener listener) {
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200711 mListener = listener;
712 }
713
Selim Cineka7d4f822016-12-06 14:34:47 -0800714 @Override
715 public boolean isInVisibleLocation(ExpandableNotificationRow row) {
716 ExpandableViewState childViewState = mCurrentStackScrollState.getViewStateForView(row);
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200717 if (childViewState == null) {
Selim Cineka7d4f822016-12-06 14:34:47 -0800718 return false;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200719 }
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100720 if ((childViewState.location & ExpandableViewState.VISIBLE_LOCATIONS) == 0) {
Selim Cineka7d4f822016-12-06 14:34:47 -0800721 return false;
Christoph Studer12cf9e52014-10-29 17:35:30 +0100722 }
Selim Cineka7d4f822016-12-06 14:34:47 -0800723 if (row.getVisibility() != View.VISIBLE) {
724 return false;
725 }
726 return true;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200727 }
728
Selim Cinek67b22602014-03-10 15:40:16 +0100729 private void setMaxLayoutHeight(int maxLayoutHeight) {
730 mMaxLayoutHeight = maxLayoutHeight;
Selim Cinek9458b192016-10-25 19:02:42 -0700731 mShelf.setMaxLayoutHeight(maxLayoutHeight);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200732 updateAlgorithmHeightAndPadding();
Selim Cinek67b22602014-03-10 15:40:16 +0100733 }
734
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200735 private void updateAlgorithmHeightAndPadding() {
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200736 mTopPadding = (int) MathUtils.lerp(mRegularTopPadding, mDarkTopPadding,
737 mInterpolatedDarkAmount);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700738 mAmbientState.setLayoutHeight(getLayoutHeight());
Selim Cinekbc243a92016-09-27 16:35:13 -0700739 updateAlgorithmLayoutMinHeight();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700740 mAmbientState.setTopPadding(mTopPadding);
Selim Cinek67b22602014-03-10 15:40:16 +0100741 }
742
Selim Cinekbc243a92016-09-27 16:35:13 -0700743 private void updateAlgorithmLayoutMinHeight() {
shawnlinc3457912018-05-15 16:39:56 +0800744 mAmbientState.setLayoutMinHeight(mQsExpanded || isHeadsUpTransition()
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800745 ? getLayoutMinHeight() : 0);
Selim Cinekbc243a92016-09-27 16:35:13 -0700746 }
747
Selim Cinek67b22602014-03-10 15:40:16 +0100748 /**
749 * Updates the children views according to the stack scroll algorithm. Call this whenever
750 * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout.
751 */
752 private void updateChildren() {
Selim Cinek3776fe02016-02-04 13:32:43 -0800753 updateScrollStateForAddedChildren();
Selim Cinek727903c2016-12-06 17:28:10 -0800754 mAmbientState.setCurrentScrollVelocity(mScroller.isFinished()
755 ? 0
756 : mScroller.getCurrVelocity());
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200757 mAmbientState.setScrollY(mOwnScrollY);
758 mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState);
Jorim Jaggi0dd68812014-05-01 19:17:37 +0200759 if (!isCurrentlyAnimating() && !mNeedsAnimation) {
Selim Cinek572bbd42014-04-25 16:43:27 +0200760 applyCurrentState();
Selim Cinek67b22602014-03-10 15:40:16 +0100761 } else {
Selim Cinekf4c19962014-05-01 21:55:31 +0200762 startAnimationToState();
Selim Cinek67b22602014-03-10 15:40:16 +0100763 }
764 }
765
Selim Cinekc383fd02016-10-21 15:31:26 -0700766 private void onPreDrawDuringAnimation() {
Selim Cineka686b2c2016-10-26 13:58:27 -0700767 mShelf.updateAppearance();
Selim Cinekb0ee18f2017-12-21 16:15:53 -0800768 updateClippingToTopRoundedCorner();
Selim Cinekc383fd02016-10-21 15:31:26 -0700769 if (!mNeedsAnimation && !mChildrenUpdateRequested) {
770 updateBackground();
771 }
Selim Cinekc383fd02016-10-21 15:31:26 -0700772 }
773
Selim Cinekb0ee18f2017-12-21 16:15:53 -0800774 private void updateClippingToTopRoundedCorner() {
Arthur Hungc0ef5652018-05-22 14:00:42 +0800775 Float clipStart = (float) mTopPadding
776 + mStackTranslation
777 + mAmbientState.getExpandAnimationTopChange();
Selim Cinekb0ee18f2017-12-21 16:15:53 -0800778 Float clipEnd = clipStart + mCornerRadius;
779 boolean first = true;
780 for (int i = 0; i < getChildCount(); i++) {
781 ExpandableView child = (ExpandableView) getChildAt(i);
782 if (child.getVisibility() == GONE) {
783 continue;
784 }
785 float start = child.getTranslationY();
Arthur Hungc0ef5652018-05-22 14:00:42 +0800786 float end = start + child.getActualHeight();
Selim Cinekb0ee18f2017-12-21 16:15:53 -0800787 boolean clip = clipStart > start && clipStart < end
788 || clipEnd >= start && clipEnd <= end;
789 clip &= !(first && mOwnScrollY == 0);
Selim Cinekeccf4942018-05-30 09:55:36 -0700790 child.setDistanceToTopRoundness(clip ? Math.max(start - clipStart, 0)
791 : ExpandableView.NO_ROUNDNESS);
Selim Cinekb0ee18f2017-12-21 16:15:53 -0800792 first = false;
793 }
794 }
795
Selim Cinek3776fe02016-02-04 13:32:43 -0800796 private void updateScrollStateForAddedChildren() {
797 if (mChildrenToAddAnimated.isEmpty()) {
798 return;
799 }
800 for (int i = 0; i < getChildCount(); i++) {
801 ExpandableView child = (ExpandableView) getChildAt(i);
802 if (mChildrenToAddAnimated.contains(child)) {
803 int startingPosition = getPositionInLinearLayout(child);
Selim Cineka7ed2c12017-01-23 20:47:24 -0800804 float increasedPaddingAmount = child.getIncreasedPaddingAmount();
805 int padding = increasedPaddingAmount == 1.0f ? mIncreasedPaddingBetweenElements
806 : increasedPaddingAmount == -1.0f ? 0 : mPaddingBetweenElements;
Selim Cinek3776fe02016-02-04 13:32:43 -0800807 int childHeight = getIntrinsicHeight(child) + padding;
808 if (startingPosition < mOwnScrollY) {
809 // This child starts off screen, so let's keep it offscreen to keep the others visible
810
Selim Cinekef406062016-09-29 17:33:13 -0700811 setOwnScrollY(mOwnScrollY + childHeight);
Selim Cinek3776fe02016-02-04 13:32:43 -0800812 }
813 }
814 }
815 clampScrollPosition();
816 }
817
Adrian Roos181385c2016-05-05 17:45:44 -0400818 private void updateForcedScroll() {
819 if (mForcedScroll != null && (!mForcedScroll.hasFocus()
820 || !mForcedScroll.isAttachedToWindow())) {
821 mForcedScroll = null;
822 }
823 if (mForcedScroll != null) {
824 ExpandableView expandableView = (ExpandableView) mForcedScroll;
825 int positionInLinearLayout = getPositionInLinearLayout(expandableView);
826 int targetScroll = targetScrollForView(expandableView, positionInLinearLayout);
Adrian Roos4a579672016-05-24 16:54:37 -0700827 int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight();
Adrian Roos181385c2016-05-05 17:45:44 -0400828
829 targetScroll = Math.max(0, Math.min(targetScroll, getScrollRange()));
Adrian Roos4a579672016-05-24 16:54:37 -0700830
831 // Only apply the scroll if we're scrolling the view upwards, or the view is so far up
832 // that it is not visible anymore.
833 if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) {
Selim Cinekef406062016-09-29 17:33:13 -0700834 setOwnScrollY(targetScroll);
Adrian Roos181385c2016-05-05 17:45:44 -0400835 }
836 }
837 }
838
Selim Cinek319bdc42014-05-01 23:01:58 +0200839 private void requestChildrenUpdate() {
Selim Cinek1f553cf2014-05-02 12:01:36 +0200840 if (!mChildrenUpdateRequested) {
841 getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater);
842 mChildrenUpdateRequested = true;
843 invalidate();
844 }
Selim Cinek319bdc42014-05-01 23:01:58 +0200845 }
846
Selim Cinek67b22602014-03-10 15:40:16 +0100847 private boolean isCurrentlyAnimating() {
Selim Cinek572bbd42014-04-25 16:43:27 +0200848 return mStateAnimator.isRunning();
Selim Cinek67b22602014-03-10 15:40:16 +0100849 }
850
Selim Cinekf7a14c02014-07-07 14:01:46 +0200851 private void clampScrollPosition() {
Selim Cinek67b22602014-03-10 15:40:16 +0100852 int scrollRange = getScrollRange();
853 if (scrollRange < mOwnScrollY) {
Selim Cinekef406062016-09-29 17:33:13 -0700854 setOwnScrollY(scrollRange);
Selim Cinek67b22602014-03-10 15:40:16 +0100855 }
856 }
857
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200858 public int getTopPadding() {
859 return mTopPadding;
860 }
861
Selim Cinek1408eb52014-06-02 14:45:38 +0200862 private void setTopPadding(int topPadding, boolean animate) {
Lucas Dupind285cf02018-01-18 09:18:23 -0800863 if (mRegularTopPadding != topPadding) {
864 mRegularTopPadding = topPadding;
865 mDarkTopPadding = topPadding + mDarkSeparatorPadding;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800866 mAmbientState.setDarkTopPadding(mDarkTopPadding);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200867 updateAlgorithmHeightAndPadding();
868 updateContentHeight();
Jorim Jaggi75c95042014-05-16 19:09:59 +0200869 if (animate && mAnimationsEnabled && mIsExpanded) {
Jorim Jaggi0dd68812014-05-01 19:17:37 +0200870 mTopPaddingNeedsAnimation = true;
871 mNeedsAnimation = true;
872 }
Selim Cinek319bdc42014-05-01 23:01:58 +0200873 requestChildrenUpdate();
Lucas Dupin60661a62018-04-12 10:50:13 -0700874 notifyHeightChangeListener(null, animate);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200875 }
876 }
877
878 /**
Selim Cinekbc243a92016-09-27 16:35:13 -0700879 * Update the height of the panel.
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200880 *
Selim Cinekbc243a92016-09-27 16:35:13 -0700881 * @param height the expanded height of the panel
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200882 */
Selim Cinekbc243a92016-09-27 16:35:13 -0700883 public void setExpandedHeight(float height) {
884 mExpandedHeight = height;
Selim Cinekcafa87f2016-10-26 17:00:17 -0700885 setIsExpanded(height > 0);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800886 int minExpansionHeight = getMinExpansionHeight();
887 if (height < minExpansionHeight) {
888 mClipRect.left = 0;
889 mClipRect.right = getWidth();
890 mClipRect.top = 0;
891 mClipRect.bottom = (int) height;
892 height = minExpansionHeight;
Selim Cinekcafa87f2016-10-26 17:00:17 -0700893 setRequestedClipBounds(mClipRect);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800894 } else {
Selim Cinekcafa87f2016-10-26 17:00:17 -0700895 setRequestedClipBounds(null);
Selim Cinek48ff9b42016-11-09 19:31:51 -0800896 }
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200897 int stackHeight;
Selim Cinek94c2d822016-07-13 18:50:04 -0700898 float translationY;
899 float appearEndPosition = getAppearEndPosition();
900 float appearStartPosition = getAppearStartPosition();
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800901 float appearFraction = 1.0f;
shawnlin5be1f7c2018-05-21 20:50:54 +0800902 boolean appearing = height < appearEndPosition;
903 mAmbientState.setAppearing(appearing);
904 if (!appearing) {
Selim Cinekbc243a92016-09-27 16:35:13 -0700905 translationY = 0;
shawnlin8e4e92c2018-04-12 18:47:24 +0800906 if (mShouldShowShelfOnly) {
907 stackHeight = mTopPadding + mShelf.getIntrinsicHeight();
908 } else if (mQsExpanded) {
909 int stackStartPosition = mContentHeight - mTopPadding + mIntrinsicPadding;
910 int stackEndPosition = mMaxTopPadding + mShelf.getIntrinsicHeight();
911 if (stackStartPosition <= stackEndPosition) {
912 stackHeight = stackEndPosition;
913 } else {
914 stackHeight = (int) NotificationUtils.interpolate(stackStartPosition,
915 stackEndPosition, mQsExpansionFraction);
916 }
917 } else {
918 stackHeight = (int) height;
919 }
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200920 } else {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800921 appearFraction = getAppearFraction(height);
Selim Cinek94c2d822016-07-13 18:50:04 -0700922 if (appearFraction >= 0) {
923 translationY = NotificationUtils.interpolate(getExpandTranslationStart(), 0,
924 appearFraction);
925 } else {
926 // This may happen when pushing up a heads up. We linearly push it up from the
927 // start
928 translationY = height - appearStartPosition + getExpandTranslationStart();
929 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800930 if (isHeadsUpTransition()) {
931 stackHeight = mFirstVisibleBackgroundChild.getPinnedHeadsUpHeight();
932 translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction);
933 } else {
934 stackHeight = (int) (height - translationY);
935 }
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200936 }
937 if (stackHeight != mCurrentStackHeight) {
938 mCurrentStackHeight = stackHeight;
939 updateAlgorithmHeightAndPadding();
Selim Cinek319bdc42014-05-01 23:01:58 +0200940 requestChildrenUpdate();
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200941 }
Selim Cinek94c2d822016-07-13 18:50:04 -0700942 setStackTranslation(translationY);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800943 for (int i = 0; i < mExpandedHeightListeners.size(); i++) {
944 BiConsumer<Float, Float> listener = mExpandedHeightListeners.get(i);
945 listener.accept(mExpandedHeight, appearFraction);
946 }
Selim Cinekcafa87f2016-10-26 17:00:17 -0700947 }
948
949 private void setRequestedClipBounds(Rect clipRect) {
950 mRequestedClipBounds = clipRect;
951 updateClipping();
952 }
953
Lucas Dupin60661a62018-04-12 10:50:13 -0700954 /**
955 * Return the height of the content ignoring the footer.
956 */
957 public int getIntrinsicContentHeight() {
958 return mIntrinsicContentHeight;
959 }
960
Selim Cinekcafa87f2016-10-26 17:00:17 -0700961 public void updateClipping() {
Jorim Jaggic4cf07a2018-07-05 18:28:12 +0200962 boolean animatingClipping = mInterpolatedDarkAmount > 0 && mInterpolatedDarkAmount < 1;
Selim Cinekcafa87f2016-10-26 17:00:17 -0700963 boolean clipped = mRequestedClipBounds != null && !mInHeadsUpPinnedMode
964 && !mHeadsUpAnimatingAway;
965 if (mIsClipped != clipped) {
966 mIsClipped = clipped;
967 updateFadingState();
968 }
Lucas Dupin16cfe452018-02-08 13:14:50 -0800969
970 if (animatingClipping) {
971 setClipBounds(mBackgroundAnimationRect);
972 } else if (clipped) {
Selim Cinekcafa87f2016-10-26 17:00:17 -0700973 setClipBounds(mRequestedClipBounds);
974 } else {
975 setClipBounds(null);
976 }
Selim Cinek94c2d822016-07-13 18:50:04 -0700977 }
978
979 /**
980 * @return The translation at the beginning when expanding.
981 * Measured relative to the resting position.
982 */
983 private float getExpandTranslationStart() {
Selim Cinek48ff9b42016-11-09 19:31:51 -0800984 return - mTopPadding;
Selim Cinek94c2d822016-07-13 18:50:04 -0700985 }
986
987 /**
988 * @return the position from where the appear transition starts when expanding.
989 * Measured in absolute height.
990 */
991 private float getAppearStartPosition() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800992 if (isHeadsUpTransition()) {
993 return mHeadsUpInset + mFirstVisibleBackgroundChild.getPinnedHeadsUpHeight();
Selim Cinekd127d792016-11-01 19:11:41 -0700994 }
Selim Cinek48ff9b42016-11-09 19:31:51 -0800995 return getMinExpansionHeight();
Selim Cinek94c2d822016-07-13 18:50:04 -0700996 }
997
998 /**
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900999 * @return the height of the top heads up notification when pinned. This is different from the
1000 * intrinsic height, which also includes whether the notification is system expanded and
1001 * is mainly used when dragging down from a heads up notification.
1002 */
1003 private int getTopHeadsUpPinnedHeight() {
1004 NotificationData.Entry topEntry = mHeadsUpManager.getTopEntry();
1005 if (topEntry == null) {
1006 return 0;
1007 }
1008 ExpandableNotificationRow row = topEntry.row;
1009 if (row.isChildInGroup()) {
1010 final ExpandableNotificationRow groupSummary
1011 = mGroupManager.getGroupSummary(row.getStatusBarNotification());
1012 if (groupSummary != null) {
1013 row = groupSummary;
1014 }
1015 }
1016 return row.getPinnedHeadsUpHeight();
1017 }
1018
1019 /**
Selim Cinek94c2d822016-07-13 18:50:04 -07001020 * @return the position from where the appear transition ends when expanding.
1021 * Measured in absolute height.
1022 */
1023 private float getAppearEndPosition() {
Selim Cinekaa417da2016-10-27 18:17:08 -07001024 int appearPosition;
Selim Cinek66440cf2017-05-26 13:48:47 -07001025 int notGoneChildCount = getNotGoneChildCount();
Julia Reynolds34f14962018-05-03 12:40:20 +00001026 if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001027 if (isHeadsUpTransition()
Selim Cinekebf42342017-07-13 15:46:10 +02001028 || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDark())) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001029 appearPosition = getTopHeadsUpPinnedHeight();
Selim Cinekcde90e52016-12-22 21:01:49 +01001030 } else {
1031 appearPosition = 0;
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001032 if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) {
1033 appearPosition += mShelf.getIntrinsicHeight();
1034 }
Selim Cinekcde90e52016-12-22 21:01:49 +01001035 }
Selim Cinekaa417da2016-10-27 18:17:08 -07001036 } else {
Selim Cinekcde90e52016-12-22 21:01:49 +01001037 appearPosition = mEmptyShadeView.getHeight();
Selim Cinekaa417da2016-10-27 18:17:08 -07001038 }
1039 return appearPosition + (onKeyguard() ? mTopPadding : mIntrinsicPadding);
Selim Cinek94c2d822016-07-13 18:50:04 -07001040 }
1041
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001042 private boolean isHeadsUpTransition() {
1043 return mTrackingHeadsUp && mFirstVisibleBackgroundChild != null
1044 && mAmbientState.isAboveShelf(mFirstVisibleBackgroundChild);
1045 }
1046
Selim Cinek94c2d822016-07-13 18:50:04 -07001047 /**
1048 * @param height the height of the panel
1049 * @return the fraction of the appear animation that has been performed
1050 */
1051 public float getAppearFraction(float height) {
1052 float appearEndPosition = getAppearEndPosition();
1053 float appearStartPosition = getAppearStartPosition();
1054 return (height - appearStartPosition)
1055 / (appearEndPosition - appearStartPosition);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001056 }
1057
Selim Cinekd2281152015-04-10 14:37:46 -07001058 public float getStackTranslation() {
1059 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001060 }
1061
Selim Cinekd2281152015-04-10 14:37:46 -07001062 private void setStackTranslation(float stackTranslation) {
1063 if (stackTranslation != mStackTranslation) {
1064 mStackTranslation = stackTranslation;
1065 mAmbientState.setStackTranslation(stackTranslation);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001066 requestChildrenUpdate();
1067 }
Selim Cinek67b22602014-03-10 15:40:16 +01001068 }
1069
1070 /**
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001071 * Get the current height of the view. This is at most the msize of the view given by a the
Selim Cinek67b22602014-03-10 15:40:16 +01001072 * layout but it can also be made smaller by setting {@link #mCurrentStackHeight}
1073 *
1074 * @return either the layout height or the externally defined height, whichever is smaller
1075 */
Selim Cinek343e6e22014-04-11 21:23:30 +02001076 private int getLayoutHeight() {
Selim Cinek67b22602014-03-10 15:40:16 +01001077 return Math.min(mMaxLayoutHeight, mCurrentStackHeight);
1078 }
1079
Selim Cinek816c8e42015-11-19 12:00:45 -08001080 public int getFirstItemMinHeight() {
1081 final ExpandableView firstChild = getFirstChildNotGone();
1082 return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize;
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001083 }
1084
Geoffrey Pitsch409db272017-08-28 14:51:52 +00001085 public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) {
Dan Sandler4247a5c2014-07-23 15:58:08 -04001086 mLongPressListener = listener;
Selim Cinek67b22602014-03-10 15:40:16 +01001087 }
1088
Jason Monk16ac3772016-02-10 15:39:21 -05001089 public void setQsContainer(ViewGroup qsContainer) {
1090 mQsContainer = qsContainer;
Jorim Jaggi56306252014-07-03 00:40:09 +02001091 }
1092
Rohan Shah524cf7b2018-03-15 14:40:02 -07001093 /**
1094 * Handles cleanup after the given {@code view} has been fully swiped out (including
1095 * re-invoking dismiss logic in case the notification has not made its way out yet).
1096 */
Mady Mellorb0a82462016-04-30 17:31:02 -07001097 @Override
Rohan Shah524cf7b2018-03-15 14:40:02 -07001098 public void onChildDismissed(View view) {
1099 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekd1395642016-04-28 12:22:42 -07001100 if (!row.isDismissed()) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07001101 handleChildViewDismissed(view);
Selim Cinekd1395642016-04-28 12:22:42 -07001102 }
1103 ViewGroup transientContainer = row.getTransientContainer();
1104 if (transientContainer != null) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07001105 transientContainer.removeTransientView(view);
Selim Cinekd1395642016-04-28 12:22:42 -07001106 }
1107 }
1108
Rohan Shah524cf7b2018-03-15 14:40:02 -07001109 /**
1110 * Starts up notification dismiss and tells the notification, if any, to remove itself from
1111 * layout.
1112 *
1113 * @param view view (e.g. notification) to dismiss from the layout
1114 */
1115 private void handleChildViewDismissed(View view) {
Dan Sandlereceda3d2014-07-21 15:35:01 -04001116 if (mDismissAllInProgress) {
1117 return;
1118 }
Rohan Shah524cf7b2018-03-15 14:40:02 -07001119
1120 boolean isBlockingHelperShown = false;
1121
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001122 setSwipingInProgress(false);
Rohan Shah524cf7b2018-03-15 14:40:02 -07001123 if (mDragAnimPendingChildren.contains(view)) {
1124 // We start the swipe and finish it in the same frame; we don't want a drag animation.
1125 mDragAnimPendingChildren.remove(view);
Selim Cinekeb973562014-05-02 17:07:49 +02001126 }
Rohan Shah524cf7b2018-03-15 14:40:02 -07001127 mAmbientState.onDragFinished(view);
Selim Cinek33223572016-02-19 19:32:22 -08001128 updateContinuousShadowDrawing();
Rohan Shah524cf7b2018-03-15 14:40:02 -07001129
1130 if (view instanceof ExpandableNotificationRow) {
1131 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001132 if (row.isHeadsUp()) {
Selim Cinek684a4422015-04-15 16:18:39 -07001133 mHeadsUpManager.addSwipedOutNotification(row.getStatusBarNotification().getKey());
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001134 }
Rohan Shah524cf7b2018-03-15 14:40:02 -07001135 isBlockingHelperShown =
1136 row.performDismissWithBlockingHelper(false /* fromAccessibility */);
yoshiki iguchi85ccbbc2018-01-22 12:33:21 +09001137 }
Blazej Magnowski72323322015-07-24 11:49:40 -07001138
Rohan Shah524cf7b2018-03-15 14:40:02 -07001139 if (!isBlockingHelperShown) {
1140 mSwipedOutViews.add(view);
1141 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001142 mFalsingManager.onNotificationDismissed();
1143 if (mFalsingManager.shouldEnforceBouncer()) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07001144 mStatusBar.executeRunnableDismissingKeyguard(
1145 null,
1146 null /* cancelAction */,
1147 false /* dismissShade */,
1148 true /* afterKeyguardGone */,
1149 false /* deferred */);
Blazej Magnowski72323322015-07-24 11:49:40 -07001150 }
Selim Cinekeb973562014-05-02 17:07:49 +02001151 }
1152
1153 @Override
Mady Mellor4b80b102016-01-22 08:03:58 -08001154 public void onChildSnappedBack(View animView, float targetLeft) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001155 mAmbientState.onDragFinished(animView);
Selim Cinek33223572016-02-19 19:32:22 -08001156 updateContinuousShadowDrawing();
Selim Cinekeb973562014-05-02 17:07:49 +02001157 if (!mDragAnimPendingChildren.contains(animView)) {
Jorim Jaggi75c95042014-05-16 19:09:59 +02001158 if (mAnimationsEnabled) {
1159 mSnappedBackChildren.add(animView);
1160 mNeedsAnimation = true;
1161 }
Selim Cinekeb973562014-05-02 17:07:49 +02001162 requestChildrenUpdate();
Selim Cinekeb973562014-05-02 17:07:49 +02001163 } else {
1164 // We start the swipe and snap back in the same frame, we don't want any animation
1165 mDragAnimPendingChildren.remove(animView);
1166 }
Mady Mellor95d743c2017-01-10 12:05:27 -08001167 if (mCurrMenuRow != null && targetLeft == 0) {
1168 mCurrMenuRow.resetMenu();
1169 mCurrMenuRow = null;
Mady Mellor4b80b102016-01-22 08:03:58 -08001170 }
Selim Cinek67b22602014-03-10 15:40:16 +01001171 }
1172
Adrian Roos5d9cc662014-05-28 17:08:13 +02001173 @Override
1174 public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
Anthony Chen7acbb772017-04-07 16:45:25 -07001175 // Returning true prevents alpha fading.
1176 return !mFadeNotificationsOnDismiss;
Adrian Roos5d9cc662014-05-28 17:08:13 +02001177 }
1178
Mady Mellorb0a82462016-04-30 17:31:02 -07001179 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001180 public void onBeginDrag(View v) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001181 mFalsingManager.onNotificatonStartDismissing();
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001182 setSwipingInProgress(true);
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001183 mAmbientState.onBeginDrag(v);
Selim Cinek33223572016-02-19 19:32:22 -08001184 updateContinuousShadowDrawing();
Selim Cinek131c1e22015-05-11 19:04:49 -07001185 if (mAnimationsEnabled && (mIsExpanded || !isPinnedHeadsUp(v))) {
Jorim Jaggi75c95042014-05-16 19:09:59 +02001186 mDragAnimPendingChildren.add(v);
1187 mNeedsAnimation = true;
1188 }
Selim Cinekeb973562014-05-02 17:07:49 +02001189 requestChildrenUpdate();
Selim Cinek67b22602014-03-10 15:40:16 +01001190 }
1191
Selim Cinek684a4422015-04-15 16:18:39 -07001192 public static boolean isPinnedHeadsUp(View v) {
Selim Cineka59ecc32015-04-07 10:51:49 -07001193 if (v instanceof ExpandableNotificationRow) {
1194 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Selim Cinek684a4422015-04-15 16:18:39 -07001195 return row.isHeadsUp() && row.isPinned();
Selim Cineka59ecc32015-04-07 10:51:49 -07001196 }
1197 return false;
1198 }
1199
1200 private boolean isHeadsUp(View v) {
1201 if (v instanceof ExpandableNotificationRow) {
1202 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
1203 return row.isHeadsUp();
1204 }
1205 return false;
1206 }
1207
Mady Mellorb0a82462016-04-30 17:31:02 -07001208 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001209 public void onDragCancelled(View v) {
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001210 mFalsingManager.onNotificatonStopDismissing();
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001211 setSwipingInProgress(false);
Selim Cinek67b22602014-03-10 15:40:16 +01001212 }
1213
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001214 @Override
1215 public float getFalsingThresholdFactor() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05001216 return mStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07001217 }
1218
Mady Mellor4b80b102016-01-22 08:03:58 -08001219 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001220 public View getChildAtPosition(MotionEvent ev) {
Mady Mellor4b80b102016-01-22 08:03:58 -08001221 View child = getChildAtPosition(ev.getX(), ev.getY());
1222 if (child instanceof ExpandableNotificationRow) {
1223 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
1224 ExpandableNotificationRow parent = row.getNotificationParent();
Selim Cinek43d30f02016-03-04 10:51:32 -08001225 if (parent != null && parent.areChildrenExpanded()
Selim Cinek38d429f2016-06-03 11:46:56 -07001226 && (parent.areGutsExposed()
Mady Mellor95d743c2017-01-10 12:05:27 -08001227 || mMenuExposedView == parent
Selim Cinek43d30f02016-03-04 10:51:32 -08001228 || (parent.getNotificationChildren().size() == 1
1229 && parent.isClearable()))) {
Mady Mellor95d743c2017-01-10 12:05:27 -08001230 // In this case the group is expanded and showing the menu for the
Mady Mellor4b80b102016-01-22 08:03:58 -08001231 // group, further interaction should apply to the group, not any
Selim Cinek43d30f02016-03-04 10:51:32 -08001232 // child notifications so we use the parent of the child. We also do the same
1233 // if we only have a single child.
1234 child = parent;
Mady Mellor4b80b102016-01-22 08:03:58 -08001235 }
1236 }
1237 return child;
Selim Cinek67b22602014-03-10 15:40:16 +01001238 }
1239
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01001240 public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) {
1241 getLocationOnScreen(mTempInt2);
1242 float localTouchY = touchY - mTempInt2[1];
1243
1244 ExpandableView closestChild = null;
1245 float minDist = Float.MAX_VALUE;
1246
1247 // find the view closest to the location, accounting for GONE views
1248 final int count = getChildCount();
1249 for (int childIdx = 0; childIdx < count; childIdx++) {
1250 ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx);
1251 if (slidingChild.getVisibility() == GONE
Selim Cinek4fd5dfc2016-01-19 15:16:15 -08001252 || slidingChild instanceof StackScrollerDecorView) {
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01001253 continue;
1254 }
1255 float childTop = slidingChild.getTranslationY();
1256 float top = childTop + slidingChild.getClipTopAmount();
Selim Cineka686b2c2016-10-26 13:58:27 -07001257 float bottom = childTop + slidingChild.getActualHeight()
1258 - slidingChild.getClipBottomAmount();
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01001259
1260 float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY));
1261 if (dist < minDist) {
1262 closestChild = slidingChild;
1263 minDist = dist;
1264 }
1265 }
1266 return closestChild;
1267 }
1268
Mady Mellorb0a82462016-04-30 17:31:02 -07001269 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001270 public ExpandableView getChildAtRawPosition(float touchX, float touchY) {
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01001271 getLocationOnScreen(mTempInt2);
1272 return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]);
Selim Cinek67b22602014-03-10 15:40:16 +01001273 }
1274
Mady Mellorb0a82462016-04-30 17:31:02 -07001275 @Override
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001276 public ExpandableView getChildAtPosition(float touchX, float touchY) {
Selim Cinek34ed7c02017-09-08 15:03:12 -07001277 return getChildAtPosition(touchX, touchY, true /* requireMinHeight */);
1278
1279 }
1280
1281 /**
1282 * Get the child at a certain screen location.
1283 *
1284 * @param touchX the x coordinate
1285 * @param touchY the y coordinate
1286 * @param requireMinHeight Whether a minimum height is required for a child to be returned.
1287 * @return the child at the given location.
1288 */
1289 private ExpandableView getChildAtPosition(float touchX, float touchY,
1290 boolean requireMinHeight) {
Selim Cinek67b22602014-03-10 15:40:16 +01001291 // find the view under the pointer, accounting for GONE views
1292 final int count = getChildCount();
1293 for (int childIdx = 0; childIdx < count; childIdx++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +02001294 ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx);
Selim Cinek51d21972017-07-19 17:39:20 -07001295 if (slidingChild.getVisibility() != VISIBLE
Selim Cinek4fd5dfc2016-01-19 15:16:15 -08001296 || slidingChild instanceof StackScrollerDecorView) {
Selim Cinek67b22602014-03-10 15:40:16 +01001297 continue;
1298 }
Selim Cinek89faff12014-06-19 16:29:04 -07001299 float childTop = slidingChild.getTranslationY();
1300 float top = childTop + slidingChild.getClipTopAmount();
Selim Cineka686b2c2016-10-26 13:58:27 -07001301 float bottom = childTop + slidingChild.getActualHeight()
1302 - slidingChild.getClipBottomAmount();
Jorim Jaggi28f0e592014-08-05 22:03:07 +02001303
1304 // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and
1305 // camera affordance).
1306 int left = 0;
1307 int right = getWidth();
Selim Cinek67b22602014-03-10 15:40:16 +01001308
Selim Cinek34ed7c02017-09-08 15:03:12 -07001309 if ((bottom - top >= mMinInteractionHeight || !requireMinHeight)
Selim Cinek51d21972017-07-19 17:39:20 -07001310 && touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) {
Selim Cinekb5605e52015-02-20 18:21:41 +01001311 if (slidingChild instanceof ExpandableNotificationRow) {
1312 ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild;
Selim Cinek131c1e22015-05-11 19:04:49 -07001313 if (!mIsExpanded && row.isHeadsUp() && row.isPinned()
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001314 && mHeadsUpManager.getTopEntry().row != row
Selim Cinek5bc852a2015-12-21 12:19:09 -08001315 && mGroupManager.getGroupSummary(
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001316 mHeadsUpManager.getTopEntry().row.getStatusBarNotification())
Selim Cinek5bc852a2015-12-21 12:19:09 -08001317 != row) {
Selim Cineka59ecc32015-04-07 10:51:49 -07001318 continue;
1319 }
Selim Cinekb5605e52015-02-20 18:21:41 +01001320 return row.getViewAtPosition(touchY - childTop);
1321 }
Selim Cinek67b22602014-03-10 15:40:16 +01001322 return slidingChild;
1323 }
1324 }
1325 return null;
1326 }
1327
Mady Mellorb0a82462016-04-30 17:31:02 -07001328 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001329 public boolean canChildBeExpanded(View v) {
1330 return v instanceof ExpandableNotificationRow
Selim Cinek8d490d42015-04-10 00:05:50 -07001331 && ((ExpandableNotificationRow) v).isExpandable()
Selim Cinek38d429f2016-06-03 11:46:56 -07001332 && !((ExpandableNotificationRow) v).areGutsExposed()
Selim Cinek166f7c42016-03-03 16:21:37 -08001333 && (mIsExpanded || !((ExpandableNotificationRow) v).isPinned());
Selim Cinek67b22602014-03-10 15:40:16 +01001334 }
1335
Chris Wren6abeeb92016-05-26 14:44:38 -04001336 /* Only ever called as a consequence of an expansion gesture in the shade. */
Mady Mellorb0a82462016-04-30 17:31:02 -07001337 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001338 public void setUserExpandedChild(View v, boolean userExpanded) {
1339 if (v instanceof ExpandableNotificationRow) {
Chris Wren6abeeb92016-05-26 14:44:38 -04001340 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Selim Cinek740c1112016-12-22 16:39:54 +01001341 if (userExpanded && onKeyguard()) {
1342 // Due to a race when locking the screen while touching, a notification may be
1343 // expanded even after we went back to keyguard. An example of this happens if
1344 // you click in the empty space while expanding a group.
1345
1346 // We also need to un-user lock it here, since otherwise the content height
1347 // calculated might be wrong. We also can't invert the two calls since
1348 // un-userlocking it will trigger a layout switch in the content view.
1349 row.setUserLocked(false);
1350 updateContentHeight();
1351 notifyHeightChangeListener(row);
1352 return;
1353 }
Chris Wren6abeeb92016-05-26 14:44:38 -04001354 row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */);
1355 row.onExpandedByGesture(userExpanded);
Selim Cinek67b22602014-03-10 15:40:16 +01001356 }
1357 }
1358
Mady Mellorb0a82462016-04-30 17:31:02 -07001359 @Override
1360 public void setExpansionCancelled(View v) {
1361 if (v instanceof ExpandableNotificationRow) {
1362 ((ExpandableNotificationRow) v).setGroupExpansionChanging(false);
1363 }
1364 }
1365
1366 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001367 public void setUserLockedChild(View v, boolean userLocked) {
1368 if (v instanceof ExpandableNotificationRow) {
1369 ((ExpandableNotificationRow) v).setUserLocked(userLocked);
1370 }
Geoffrey Pitsch409db272017-08-28 14:51:52 +00001371 cancelLongPress();
Selim Cinek1408eb52014-06-02 14:45:38 +02001372 requestDisallowInterceptTouchEvent(true);
1373 }
1374
1375 @Override
1376 public void expansionStateChanged(boolean isExpanding) {
1377 mExpandingNotification = isExpanding;
1378 if (!mExpandedInThisMotion) {
1379 mMaxScrollAfterExpand = mOwnScrollY;
1380 mExpandedInThisMotion = true;
1381 }
1382 }
1383
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001384 @Override
1385 public int getMaxExpandHeight(ExpandableView view) {
Selim Cinekb3dadcc2016-11-21 17:21:13 -08001386 return view.getMaxContentHeight();
Selim Cinek1b2a05e2016-04-28 14:20:39 -07001387 }
1388
Selim Cinek1408eb52014-06-02 14:45:38 +02001389 public void setScrollingEnabled(boolean enable) {
1390 mScrollingEnabled = enable;
1391 }
1392
Adrian Roos181385c2016-05-05 17:45:44 -04001393 public void lockScrollTo(View v) {
1394 if (mForcedScroll == v) {
1395 return;
1396 }
1397 mForcedScroll = v;
1398 scrollTo(v);
1399 }
1400
Ricky Waicd35def2016-05-03 11:07:07 +01001401 public boolean scrollTo(View v) {
Adrian Roos5153d4a2016-03-22 10:01:56 -07001402 ExpandableView expandableView = (ExpandableView) v;
Adrian Roos4a579672016-05-24 16:54:37 -07001403 int positionInLinearLayout = getPositionInLinearLayout(v);
1404 int targetScroll = targetScrollForView(expandableView, positionInLinearLayout);
1405 int outOfViewScroll = positionInLinearLayout + expandableView.getIntrinsicHeight();
Ricky Waicd35def2016-05-03 11:07:07 +01001406
Adrian Roos4a579672016-05-24 16:54:37 -07001407 // Only apply the scroll if we're scrolling the view upwards, or the view is so far up
1408 // that it is not visible anymore.
1409 if (mOwnScrollY < targetScroll || outOfViewScroll < mOwnScrollY) {
Adrian Roos5153d4a2016-03-22 10:01:56 -07001410 mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScroll - mOwnScrollY);
1411 mDontReportNextOverScroll = true;
Selim Cinek9212de82017-02-06 16:04:28 -08001412 animateScroll();
Ricky Waicd35def2016-05-03 11:07:07 +01001413 return true;
Adrian Roos5153d4a2016-03-22 10:01:56 -07001414 }
Ricky Waicd35def2016-05-03 11:07:07 +01001415 return false;
Adrian Roos5153d4a2016-03-22 10:01:56 -07001416 }
1417
Adrian Roos181385c2016-05-05 17:45:44 -04001418 /**
1419 * @return the scroll necessary to make the bottom edge of {@param v} align with the top of
1420 * the IME.
1421 */
1422 private int targetScrollForView(ExpandableView v, int positionInLinearLayout) {
1423 return positionInLinearLayout + v.getIntrinsicHeight() +
1424 getImeInset() - getHeight() + getTopPadding();
1425 }
1426
Adrian Roos5153d4a2016-03-22 10:01:56 -07001427 @Override
1428 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Selim Cineka424c502016-04-05 13:07:54 -07001429 mBottomInset = insets.getSystemWindowInsetBottom();
Adrian Roos5153d4a2016-03-22 10:01:56 -07001430
1431 int range = getScrollRange();
1432 if (mOwnScrollY > range) {
1433 // HACK: We're repeatedly getting staggered insets here while the IME is
1434 // animating away. To work around that we'll wait until things have settled.
1435 removeCallbacks(mReclamp);
1436 postDelayed(mReclamp, 50);
Adrian Roos4a579672016-05-24 16:54:37 -07001437 } else if (mForcedScroll != null) {
1438 // The scroll was requested before we got the actual inset - in case we need
1439 // to scroll up some more do so now.
1440 scrollTo(mForcedScroll);
Adrian Roos5153d4a2016-03-22 10:01:56 -07001441 }
1442 return insets;
1443 }
1444
1445 private Runnable mReclamp = new Runnable() {
1446 @Override
1447 public void run() {
1448 int range = getScrollRange();
1449 mScroller.startScroll(mScrollX, mOwnScrollY, 0, range - mOwnScrollY);
1450 mDontReportNextOverScroll = true;
1451 mDontClampNextScroll = true;
Selim Cinek9212de82017-02-06 16:04:28 -08001452 animateScroll();
Adrian Roos5153d4a2016-03-22 10:01:56 -07001453 }
1454 };
1455
Selim Cinek1408eb52014-06-02 14:45:38 +02001456 public void setExpandingEnabled(boolean enable) {
1457 mExpandHelper.setEnabled(enable);
1458 }
1459
1460 private boolean isScrollingEnabled() {
1461 return mScrollingEnabled;
Selim Cinek67b22602014-03-10 15:40:16 +01001462 }
1463
Mady Mellorb0a82462016-04-30 17:31:02 -07001464 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001465 public boolean canChildBeDismissed(View v) {
Selim Cinek9c17b772015-07-07 20:37:09 -07001466 return StackScrollAlgorithm.canChildBeDismissed(v);
Selim Cinek67b22602014-03-10 15:40:16 +01001467 }
1468
Selim Cinek19c8c702014-08-25 22:09:19 +02001469 @Override
1470 public boolean isAntiFalsingNeeded() {
Selim Cinekbc243a92016-09-27 16:35:13 -07001471 return onKeyguard();
1472 }
1473
1474 private boolean onKeyguard() {
Selim Cinek355652a2016-12-07 13:32:12 -08001475 return mStatusBarState == StatusBarState.KEYGUARD;
Selim Cinek19c8c702014-08-25 22:09:19 +02001476 }
1477
Selim Cinekb6d85eb2014-03-28 20:21:01 +01001478 private void setSwipingInProgress(boolean isSwiped) {
1479 mSwipingInProgress = isSwiped;
1480 if(isSwiped) {
1481 requestDisallowInterceptTouchEvent(true);
1482 }
Selim Cinek67b22602014-03-10 15:40:16 +01001483 }
1484
1485 @Override
1486 protected void onConfigurationChanged(Configuration newConfig) {
1487 super.onConfigurationChanged(newConfig);
Adrian Roos22af6502018-02-22 16:57:08 +01001488 mStatusBarHeight = getResources().getDimensionPixelOffset(R.dimen.status_bar_height);
Selim Cinek67b22602014-03-10 15:40:16 +01001489 float densityScale = getResources().getDisplayMetrics().density;
1490 mSwipeHelper.setDensityScale(densityScale);
1491 float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
1492 mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
1493 initView(getContext());
1494 }
1495
Dan Sandlereceda3d2014-07-21 15:35:01 -04001496 public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) {
Mady Mellor9c2c4962016-04-05 10:43:08 -07001497 mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration,
1498 true /* isDismissAll */);
Selim Cinek67b22602014-03-10 15:40:16 +01001499 }
1500
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09001501 @Override
Mady Mellor86889c22016-04-18 16:37:06 -07001502 public void snapViewIfNeeded(ExpandableNotificationRow child) {
dongwan0605.kim30637e42016-03-02 17:16:47 +09001503 boolean animate = mIsExpanded || isPinnedHeadsUp(child);
Mady Mellor95d743c2017-01-10 12:05:27 -08001504 // If the child is showing the notification menu snap to that
1505 float targetLeft = child.getProvider().isMenuVisible() ? child.getTranslation() : 0;
Mady Mellor86889c22016-04-18 16:37:06 -07001506 mSwipeHelper.snapChildIfNeeded(child, animate, targetLeft);
dongwan0605.kim30637e42016-03-02 17:16:47 +09001507 }
1508
Selim Cinek67b22602014-03-10 15:40:16 +01001509 @Override
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09001510 public ViewGroup getViewParentForNotification(NotificationData.Entry entry) {
1511 return this;
1512 }
1513
1514 @Override
Selim Cinek67b22602014-03-10 15:40:16 +01001515 public boolean onTouchEvent(MotionEvent ev) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001516 boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL
1517 || ev.getActionMasked()== MotionEvent.ACTION_UP;
Selim Cinek3a9c10a2014-10-28 14:21:10 +01001518 handleEmptySpaceClick(ev);
Selim Cinek1408eb52014-06-02 14:45:38 +02001519 boolean expandWantsIt = false;
Selim Cinekcb9400a2015-06-03 16:56:13 +02001520 if (mIsExpanded && !mSwipingInProgress && !mOnlyScrollingInThisMotion) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001521 if (isCancelOrUp) {
1522 mExpandHelper.onlyObserveMovements(false);
1523 }
1524 boolean wasExpandingBefore = mExpandingNotification;
1525 expandWantsIt = mExpandHelper.onTouchEvent(ev);
Selim Cinekf7a14c02014-07-07 14:01:46 +02001526 if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore
1527 && !mDisallowScrollingInThisMotion) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001528 dispatchDownEventToScroller(ev);
1529 }
1530 }
Selim Cinek67b22602014-03-10 15:40:16 +01001531 boolean scrollerWantsIt = false;
Selim Cinek684a4422015-04-15 16:18:39 -07001532 if (mIsExpanded && !mSwipingInProgress && !mExpandingNotification
1533 && !mDisallowScrollingInThisMotion) {
Selim Cinek67b22602014-03-10 15:40:16 +01001534 scrollerWantsIt = onScrollTouch(ev);
1535 }
1536 boolean horizontalSwipeWantsIt = false;
Selim Cinek1408eb52014-06-02 14:45:38 +02001537 if (!mIsBeingDragged
1538 && !mExpandingNotification
1539 && !mExpandedInThisMotion
Adrian Roosfa139752016-04-27 09:59:08 -07001540 && !mOnlyScrollingInThisMotion
1541 && !mDisallowDismissInThisMotion) {
Selim Cinek67b22602014-03-10 15:40:16 +01001542 horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev);
1543 }
Mady Mellorc2dbe492017-03-30 13:22:03 -07001544
1545 // Check if we need to clear any snooze leavebehinds
Eliot Courtney47098cb2017-10-18 17:30:30 +09001546 NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts();
Mady Mellorc2dbe492017-03-30 13:22:03 -07001547 if (guts != null && !isTouchInView(ev, guts)
1548 && guts.getGutsContent() instanceof NotificationSnooze) {
1549 NotificationSnooze ns = (NotificationSnooze) guts.getGutsContent();
1550 if ((ns.isExpanded() && isCancelOrUp)
1551 || (!horizontalSwipeWantsIt && scrollerWantsIt)) {
1552 // If the leavebehind is expanded we clear it on the next up event, otherwise we
1553 // clear it on the next non-horizontal swipe or expand event.
1554 checkSnoozeLeavebehind();
1555 }
1556 }
1557 if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
1558 mCheckForLeavebehind = true;
1559 }
Selim Cinek1408eb52014-06-02 14:45:38 +02001560 return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev);
1561 }
1562
1563 private void dispatchDownEventToScroller(MotionEvent ev) {
1564 MotionEvent downEvent = MotionEvent.obtain(ev);
1565 downEvent.setAction(MotionEvent.ACTION_DOWN);
1566 onScrollTouch(downEvent);
1567 downEvent.recycle();
Selim Cinek67b22602014-03-10 15:40:16 +01001568 }
1569
Selim Cinek11e33232016-08-05 15:30:53 -07001570 @Override
1571 public boolean onGenericMotionEvent(MotionEvent event) {
1572 if (!isScrollingEnabled() || !mIsExpanded || mSwipingInProgress || mExpandingNotification
1573 || mDisallowScrollingInThisMotion) {
1574 return false;
1575 }
1576 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
1577 switch (event.getAction()) {
1578 case MotionEvent.ACTION_SCROLL: {
1579 if (!mIsBeingDragged) {
1580 final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
1581 if (vscroll != 0) {
1582 final int delta = (int) (vscroll * getVerticalScrollFactor());
1583 final int range = getScrollRange();
1584 int oldScrollY = mOwnScrollY;
1585 int newScrollY = oldScrollY - delta;
1586 if (newScrollY < 0) {
1587 newScrollY = 0;
1588 } else if (newScrollY > range) {
1589 newScrollY = range;
1590 }
1591 if (newScrollY != oldScrollY) {
Selim Cinek9212de82017-02-06 16:04:28 -08001592 setOwnScrollY(newScrollY);
Selim Cinek11e33232016-08-05 15:30:53 -07001593 return true;
1594 }
1595 }
1596 }
1597 }
1598 }
1599 }
1600 return super.onGenericMotionEvent(event);
1601 }
1602
Selim Cinek67b22602014-03-10 15:40:16 +01001603 private boolean onScrollTouch(MotionEvent ev) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001604 if (!isScrollingEnabled()) {
1605 return false;
1606 }
Adrian Roosfeb97252016-09-29 17:05:58 -07001607 if (isInsideQsContainer(ev) && !mIsBeingDragged) {
Jason Monk16ac3772016-02-10 15:39:21 -05001608 return false;
1609 }
Adrian Roos181385c2016-05-05 17:45:44 -04001610 mForcedScroll = null;
Selim Cinek67b22602014-03-10 15:40:16 +01001611 initVelocityTrackerIfNotExists();
1612 mVelocityTracker.addMovement(ev);
1613
1614 final int action = ev.getAction();
1615
1616 switch (action & MotionEvent.ACTION_MASK) {
1617 case MotionEvent.ACTION_DOWN: {
Jorim Jaggife6bfa62014-05-07 23:23:18 +02001618 if (getChildCount() == 0 || !isInContentBounds(ev)) {
Selim Cinek67b22602014-03-10 15:40:16 +01001619 return false;
1620 }
1621 boolean isBeingDragged = !mScroller.isFinished();
1622 setIsBeingDragged(isBeingDragged);
Selim Cinek67b22602014-03-10 15:40:16 +01001623 /*
1624 * If being flinged and user touches, stop the fling. isFinished
1625 * will be false if being flinged.
1626 */
1627 if (!mScroller.isFinished()) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001628 mScroller.forceFinished(true);
Selim Cinek67b22602014-03-10 15:40:16 +01001629 }
1630
1631 // Remember where the motion event started
1632 mLastMotionY = (int) ev.getY();
Selim Cinek1408eb52014-06-02 14:45:38 +02001633 mDownX = (int) ev.getX();
Selim Cinek67b22602014-03-10 15:40:16 +01001634 mActivePointerId = ev.getPointerId(0);
1635 break;
1636 }
1637 case MotionEvent.ACTION_MOVE:
1638 final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
1639 if (activePointerIndex == -1) {
1640 Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
1641 break;
1642 }
1643
1644 final int y = (int) ev.getY(activePointerIndex);
Selim Cinek1408eb52014-06-02 14:45:38 +02001645 final int x = (int) ev.getX(activePointerIndex);
Selim Cinek67b22602014-03-10 15:40:16 +01001646 int deltaY = mLastMotionY - y;
Selim Cinek1408eb52014-06-02 14:45:38 +02001647 final int xDiff = Math.abs(x - mDownX);
1648 final int yDiff = Math.abs(deltaY);
1649 if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) {
Selim Cinek67b22602014-03-10 15:40:16 +01001650 setIsBeingDragged(true);
1651 if (deltaY > 0) {
1652 deltaY -= mTouchSlop;
1653 } else {
1654 deltaY += mTouchSlop;
1655 }
1656 }
1657 if (mIsBeingDragged) {
1658 // Scroll to follow the motion event
1659 mLastMotionY = y;
Selim Cinek1408eb52014-06-02 14:45:38 +02001660 int range = getScrollRange();
1661 if (mExpandedInThisMotion) {
1662 range = Math.min(range, mMaxScrollAfterExpand);
1663 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001664
1665 float scrollAmount;
1666 if (deltaY < 0) {
1667 scrollAmount = overScrollDown(deltaY);
1668 } else {
1669 scrollAmount = overScrollUp(deltaY, range);
1670 }
Selim Cinek67b22602014-03-10 15:40:16 +01001671
Selim Cinek9212de82017-02-06 16:04:28 -08001672 // Calling customOverScrollBy will call onCustomOverScrolled, which
1673 // sets the scrolling if applicable.
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001674 if (scrollAmount != 0.0f) {
1675 // The scrolling motion could not be compensated with the
1676 // existing overScroll, we have to scroll the view
Selim Cinek9212de82017-02-06 16:04:28 -08001677 customOverScrollBy((int) scrollAmount, mOwnScrollY,
1678 range, getHeight() / 2);
Mady Mellorc2dbe492017-03-30 13:22:03 -07001679 // If we're scrolling, leavebehinds should be dismissed
1680 checkSnoozeLeavebehind();
Selim Cinek67b22602014-03-10 15:40:16 +01001681 }
Selim Cinek67b22602014-03-10 15:40:16 +01001682 }
1683 break;
1684 case MotionEvent.ACTION_UP:
1685 if (mIsBeingDragged) {
1686 final VelocityTracker velocityTracker = mVelocityTracker;
1687 velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
1688 int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);
1689
Selim Cinek1408eb52014-06-02 14:45:38 +02001690 if (shouldOverScrollFling(initialVelocity)) {
1691 onOverScrollFling(true, initialVelocity);
1692 } else {
1693 if (getChildCount() > 0) {
1694 if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
1695 float currentOverScrollTop = getCurrentOverScrollAmount(true);
1696 if (currentOverScrollTop == 0.0f || initialVelocity > 0) {
1697 fling(-initialVelocity);
1698 } else {
1699 onOverScrollFling(false, initialVelocity);
1700 }
1701 } else {
1702 if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0,
1703 getScrollRange())) {
Selim Cinek9212de82017-02-06 16:04:28 -08001704 animateScroll();
Selim Cinek1408eb52014-06-02 14:45:38 +02001705 }
Selim Cinek67b22602014-03-10 15:40:16 +01001706 }
1707 }
Selim Cinek1408eb52014-06-02 14:45:38 +02001708 }
Selim Cinek48e746c2014-06-16 16:01:03 -07001709 mActivePointerId = INVALID_POINTER;
1710 endDrag();
Selim Cinek67b22602014-03-10 15:40:16 +01001711 }
Selim Cinek48e746c2014-06-16 16:01:03 -07001712
Selim Cinek67b22602014-03-10 15:40:16 +01001713 break;
1714 case MotionEvent.ACTION_CANCEL:
1715 if (mIsBeingDragged && getChildCount() > 0) {
1716 if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) {
Selim Cinek9212de82017-02-06 16:04:28 -08001717 animateScroll();
Selim Cinek67b22602014-03-10 15:40:16 +01001718 }
1719 mActivePointerId = INVALID_POINTER;
1720 endDrag();
1721 }
1722 break;
1723 case MotionEvent.ACTION_POINTER_DOWN: {
1724 final int index = ev.getActionIndex();
1725 mLastMotionY = (int) ev.getY(index);
Selim Cinek1408eb52014-06-02 14:45:38 +02001726 mDownX = (int) ev.getX(index);
Selim Cinek67b22602014-03-10 15:40:16 +01001727 mActivePointerId = ev.getPointerId(index);
1728 break;
1729 }
1730 case MotionEvent.ACTION_POINTER_UP:
1731 onSecondaryPointerUp(ev);
1732 mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId));
Selim Cinek1408eb52014-06-02 14:45:38 +02001733 mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId));
Selim Cinek67b22602014-03-10 15:40:16 +01001734 break;
1735 }
1736 return true;
1737 }
1738
Muyuan Li84b45612016-06-01 11:05:08 -07001739 protected boolean isInsideQsContainer(MotionEvent ev) {
1740 return ev.getY() < mQsContainer.getBottom();
1741 }
1742
Selim Cinek1408eb52014-06-02 14:45:38 +02001743 private void onOverScrollFling(boolean open, int initialVelocity) {
1744 if (mOverscrollTopChangedListener != null) {
1745 mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open);
1746 }
1747 mDontReportNextOverScroll = true;
1748 setOverScrollAmount(0.0f, true, false);
1749 }
1750
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001751 /**
1752 * Perform a scroll upwards and adapt the overscroll amounts accordingly
1753 *
1754 * @param deltaY The amount to scroll upwards, has to be positive.
1755 * @return The amount of scrolling to be performed by the scroller,
1756 * not handled by the overScroll amount.
1757 */
1758 private float overScrollUp(int deltaY, int range) {
1759 deltaY = Math.max(deltaY, 0);
1760 float currentTopAmount = getCurrentOverScrollAmount(true);
1761 float newTopAmount = currentTopAmount - deltaY;
1762 if (currentTopAmount > 0) {
1763 setOverScrollAmount(newTopAmount, true /* onTop */,
1764 false /* animate */);
1765 }
1766 // Top overScroll might not grab all scrolling motion,
1767 // we have to scroll as well.
1768 float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f;
1769 float newScrollY = mOwnScrollY + scrollAmount;
1770 if (newScrollY > range) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001771 if (!mExpandedInThisMotion) {
1772 float currentBottomPixels = getCurrentOverScrolledPixels(false);
1773 // We overScroll on the top
1774 setOverScrolledPixels(currentBottomPixels + newScrollY - range,
1775 false /* onTop */,
1776 false /* animate */);
1777 }
Selim Cinekef406062016-09-29 17:33:13 -07001778 setOwnScrollY(range);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001779 scrollAmount = 0.0f;
1780 }
1781 return scrollAmount;
1782 }
1783
1784 /**
1785 * Perform a scroll downward and adapt the overscroll amounts accordingly
1786 *
1787 * @param deltaY The amount to scroll downwards, has to be negative.
1788 * @return The amount of scrolling to be performed by the scroller,
1789 * not handled by the overScroll amount.
1790 */
1791 private float overScrollDown(int deltaY) {
1792 deltaY = Math.min(deltaY, 0);
1793 float currentBottomAmount = getCurrentOverScrollAmount(false);
1794 float newBottomAmount = currentBottomAmount + deltaY;
1795 if (currentBottomAmount > 0) {
1796 setOverScrollAmount(newBottomAmount, false /* onTop */,
1797 false /* animate */);
1798 }
1799 // Bottom overScroll might not grab all scrolling motion,
1800 // we have to scroll as well.
1801 float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f;
1802 float newScrollY = mOwnScrollY + scrollAmount;
1803 if (newScrollY < 0) {
1804 float currentTopPixels = getCurrentOverScrolledPixels(true);
1805 // We overScroll on the top
1806 setOverScrolledPixels(currentTopPixels - newScrollY,
1807 true /* onTop */,
1808 false /* animate */);
Selim Cinekef406062016-09-29 17:33:13 -07001809 setOwnScrollY(0);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001810 scrollAmount = 0.0f;
1811 }
1812 return scrollAmount;
1813 }
1814
Selim Cinek67b22602014-03-10 15:40:16 +01001815 private void onSecondaryPointerUp(MotionEvent ev) {
1816 final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
1817 MotionEvent.ACTION_POINTER_INDEX_SHIFT;
1818 final int pointerId = ev.getPointerId(pointerIndex);
1819 if (pointerId == mActivePointerId) {
1820 // This was our active pointer going up. Choose a new
1821 // active pointer and adjust accordingly.
1822 // TODO: Make this decision more intelligent.
1823 final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
1824 mLastMotionY = (int) ev.getY(newPointerIndex);
1825 mActivePointerId = ev.getPointerId(newPointerIndex);
1826 if (mVelocityTracker != null) {
1827 mVelocityTracker.clear();
1828 }
1829 }
1830 }
1831
1832 private void initVelocityTrackerIfNotExists() {
1833 if (mVelocityTracker == null) {
1834 mVelocityTracker = VelocityTracker.obtain();
1835 }
1836 }
1837
1838 private void recycleVelocityTracker() {
1839 if (mVelocityTracker != null) {
1840 mVelocityTracker.recycle();
1841 mVelocityTracker = null;
1842 }
1843 }
1844
1845 private void initOrResetVelocityTracker() {
1846 if (mVelocityTracker == null) {
1847 mVelocityTracker = VelocityTracker.obtain();
1848 } else {
1849 mVelocityTracker.clear();
1850 }
1851 }
1852
Ricky Waicd35def2016-05-03 11:07:07 +01001853 public void setFinishScrollingCallback(Runnable runnable) {
1854 mFinishScrollingCallback = runnable;
1855 }
1856
Selim Cinek9212de82017-02-06 16:04:28 -08001857 private void animateScroll() {
Selim Cinek67b22602014-03-10 15:40:16 +01001858 if (mScroller.computeScrollOffset()) {
Selim Cinek67b22602014-03-10 15:40:16 +01001859 int oldY = mOwnScrollY;
Selim Cinek67b22602014-03-10 15:40:16 +01001860 int y = mScroller.getCurrY();
1861
Selim Cinek9212de82017-02-06 16:04:28 -08001862 if (oldY != y) {
Adrian Roos5153d4a2016-03-22 10:01:56 -07001863 int range = getScrollRange();
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001864 if (y < 0 && oldY >= 0 || y > range && oldY <= range) {
1865 float currVelocity = mScroller.getCurrVelocity();
Selim Cinekba819622014-05-13 17:55:53 +02001866 if (currVelocity >= mMinimumVelocity) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001867 mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance;
1868 }
1869 }
Selim Cinek67b22602014-03-10 15:40:16 +01001870
Adrian Roos5153d4a2016-03-22 10:01:56 -07001871 if (mDontClampNextScroll) {
1872 range = Math.max(range, oldY);
1873 }
Selim Cinek9212de82017-02-06 16:04:28 -08001874 customOverScrollBy(y - oldY, oldY, range,
1875 (int) (mMaxOverScroll));
Selim Cinek67b22602014-03-10 15:40:16 +01001876 }
1877
Selim Cinek9212de82017-02-06 16:04:28 -08001878 postOnAnimation(mAnimateScroll);
Adrian Roos5153d4a2016-03-22 10:01:56 -07001879 } else {
1880 mDontClampNextScroll = false;
Ricky Waicd35def2016-05-03 11:07:07 +01001881 if (mFinishScrollingCallback != null) {
1882 mFinishScrollingCallback.run();
1883 }
Selim Cinek67b22602014-03-10 15:40:16 +01001884 }
1885 }
1886
Selim Cinek9212de82017-02-06 16:04:28 -08001887 private boolean customOverScrollBy(int deltaY, int scrollY, int scrollRangeY,
1888 int maxOverScrollY) {
Selim Cinek4195dd02014-05-19 18:16:14 +02001889
1890 int newScrollY = scrollY + deltaY;
Selim Cinek4195dd02014-05-19 18:16:14 +02001891 final int top = -maxOverScrollY;
1892 final int bottom = maxOverScrollY + scrollRangeY;
1893
1894 boolean clampedY = false;
1895 if (newScrollY > bottom) {
1896 newScrollY = bottom;
1897 clampedY = true;
1898 } else if (newScrollY < top) {
1899 newScrollY = top;
1900 clampedY = true;
1901 }
1902
Selim Cinek9212de82017-02-06 16:04:28 -08001903 onCustomOverScrolled(newScrollY, clampedY);
Selim Cinek4195dd02014-05-19 18:16:14 +02001904
1905 return clampedY;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001906 }
1907
1908 /**
1909 * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded
1910 * overscroll effect based on numPixels. By default this will also cancel animations on the
1911 * same overScroll edge.
1912 *
1913 * @param numPixels The amount of pixels to overScroll by. These will be scaled according to
1914 * the rubber-banding logic.
1915 * @param onTop Should the effect be applied on top of the scroller.
1916 * @param animate Should an animation be performed.
1917 */
1918 public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) {
Selim Cinekfed1ab62014-06-17 14:10:33 -07001919 setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001920 }
1921
1922 /**
1923 * Set the effective overScroll amount which will be directly reflected in the layout.
1924 * By default this will also cancel animations on the same overScroll edge.
1925 *
1926 * @param amount The amount to overScroll by.
1927 * @param onTop Should the effect be applied on top of the scroller.
1928 * @param animate Should an animation be performed.
1929 */
1930 public void setOverScrollAmount(float amount, boolean onTop, boolean animate) {
1931 setOverScrollAmount(amount, onTop, animate, true);
1932 }
1933
1934 /**
1935 * Set the effective overScroll amount which will be directly reflected in the layout.
1936 *
1937 * @param amount The amount to overScroll by.
1938 * @param onTop Should the effect be applied on top of the scroller.
1939 * @param animate Should an animation be performed.
1940 * @param cancelAnimators Should running animations be cancelled.
1941 */
1942 public void setOverScrollAmount(float amount, boolean onTop, boolean animate,
1943 boolean cancelAnimators) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001944 setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop));
1945 }
1946
1947 /**
1948 * Set the effective overScroll amount which will be directly reflected in the layout.
1949 *
1950 * @param amount The amount to overScroll by.
1951 * @param onTop Should the effect be applied on top of the scroller.
1952 * @param animate Should an animation be performed.
1953 * @param cancelAnimators Should running animations be cancelled.
1954 * @param isRubberbanded The value which will be passed to
1955 * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged}
1956 */
1957 public void setOverScrollAmount(float amount, boolean onTop, boolean animate,
1958 boolean cancelAnimators, boolean isRubberbanded) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001959 if (cancelAnimators) {
1960 mStateAnimator.cancelOverScrollAnimators(onTop);
1961 }
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001962 setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001963 }
1964
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001965 private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate,
1966 boolean isRubberbanded) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001967 amount = Math.max(0, amount);
1968 if (animate) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001969 mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001970 } else {
Selim Cinekfed1ab62014-06-17 14:10:33 -07001971 setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001972 mAmbientState.setOverScrollAmount(amount, onTop);
Jorim Jaggi290600a2014-05-30 17:02:20 +02001973 if (onTop) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001974 notifyOverscrollTopListener(amount, isRubberbanded);
Jorim Jaggi290600a2014-05-30 17:02:20 +02001975 }
Selim Cinek1408eb52014-06-02 14:45:38 +02001976 requestChildrenUpdate();
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001977 }
1978 }
1979
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001980 private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) {
Selim Cinek1408eb52014-06-02 14:45:38 +02001981 mExpandHelper.onlyObserveMovements(amount > 1.0f);
1982 if (mDontReportNextOverScroll) {
1983 mDontReportNextOverScroll = false;
1984 return;
1985 }
Jorim Jaggi290600a2014-05-30 17:02:20 +02001986 if (mOverscrollTopChangedListener != null) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02001987 mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded);
Jorim Jaggi290600a2014-05-30 17:02:20 +02001988 }
1989 }
1990
1991 public void setOverscrollTopChangedListener(
1992 OnOverscrollTopChangedListener overscrollTopChangedListener) {
1993 mOverscrollTopChangedListener = overscrollTopChangedListener;
1994 }
1995
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02001996 public float getCurrentOverScrollAmount(boolean top) {
1997 return mAmbientState.getOverScrollAmount(top);
1998 }
1999
2000 public float getCurrentOverScrolledPixels(boolean top) {
2001 return top? mOverScrolledTopPixels : mOverScrolledBottomPixels;
2002 }
2003
2004 private void setOverScrolledPixels(float amount, boolean onTop) {
2005 if (onTop) {
2006 mOverScrolledTopPixels = amount;
2007 } else {
2008 mOverScrolledBottomPixels = amount;
2009 }
2010 }
2011
Selim Cinek9212de82017-02-06 16:04:28 -08002012 private void onCustomOverScrolled(int scrollY, boolean clampedY) {
Selim Cinek67b22602014-03-10 15:40:16 +01002013 // Treat animating scrolls differently; see #computeScroll() for why.
2014 if (!mScroller.isFinished()) {
Selim Cinekef406062016-09-29 17:33:13 -07002015 setOwnScrollY(scrollY);
Selim Cinek67b22602014-03-10 15:40:16 +01002016 if (clampedY) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002017 springBack();
2018 } else {
Jorim Jaggi290600a2014-05-30 17:02:20 +02002019 float overScrollTop = getCurrentOverScrollAmount(true);
2020 if (mOwnScrollY < 0) {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02002021 notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true));
Jorim Jaggi290600a2014-05-30 17:02:20 +02002022 } else {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02002023 notifyOverscrollTopListener(overScrollTop, isRubberbanded(true));
Jorim Jaggi290600a2014-05-30 17:02:20 +02002024 }
Selim Cinek67b22602014-03-10 15:40:16 +01002025 }
Selim Cinek67b22602014-03-10 15:40:16 +01002026 } else {
Selim Cinek9212de82017-02-06 16:04:28 -08002027 setOwnScrollY(scrollY);
Selim Cinek67b22602014-03-10 15:40:16 +01002028 }
2029 }
2030
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002031 private void springBack() {
2032 int scrollRange = getScrollRange();
2033 boolean overScrolledTop = mOwnScrollY <= 0;
2034 boolean overScrolledBottom = mOwnScrollY >= scrollRange;
2035 if (overScrolledTop || overScrolledBottom) {
2036 boolean onTop;
2037 float newAmount;
2038 if (overScrolledTop) {
2039 onTop = true;
2040 newAmount = -mOwnScrollY;
Selim Cinekef406062016-09-29 17:33:13 -07002041 setOwnScrollY(0);
Selim Cinek1408eb52014-06-02 14:45:38 +02002042 mDontReportNextOverScroll = true;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002043 } else {
2044 onTop = false;
2045 newAmount = mOwnScrollY - scrollRange;
Selim Cinekef406062016-09-29 17:33:13 -07002046 setOwnScrollY(scrollRange);
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002047 }
2048 setOverScrollAmount(newAmount, onTop, false);
2049 setOverScrollAmount(0.0f, onTop, true);
2050 mScroller.forceFinished(true);
2051 }
2052 }
2053
Selim Cinek67b22602014-03-10 15:40:16 +01002054 private int getScrollRange() {
Selim Cinekf4b04ae2018-06-13 18:23:45 -07002055 int scrollRange = Math.max(0, mContentHeight - mMaxLayoutHeight);
Selim Cineka424c502016-04-05 13:07:54 -07002056 int imeInset = getImeInset();
Selim Cinekf4b04ae2018-06-13 18:23:45 -07002057 scrollRange += Math.min(imeInset, Math.max(0, mContentHeight - (getHeight() - imeInset)));
Selim Cineka424c502016-04-05 13:07:54 -07002058 return scrollRange;
2059 }
2060
2061 private int getImeInset() {
2062 return Math.max(0, mBottomInset - (getRootView().getHeight() - getHeight()));
Selim Cinek67b22602014-03-10 15:40:16 +01002063 }
2064
Selim Cinek343e6e22014-04-11 21:23:30 +02002065 /**
2066 * @return the first child which has visibility unequal to GONE
2067 */
Selim Cinekb55386d2015-12-16 17:26:49 -08002068 public ExpandableView getFirstChildNotGone() {
Selim Cinek343e6e22014-04-11 21:23:30 +02002069 int childCount = getChildCount();
2070 for (int i = 0; i < childCount; i++) {
2071 View child = getChildAt(i);
Selim Cinekdb167372016-11-17 15:41:17 -08002072 if (child.getVisibility() != View.GONE && child != mShelf) {
Selim Cinek816c8e42015-11-19 12:00:45 -08002073 return (ExpandableView) child;
Selim Cinek343e6e22014-04-11 21:23:30 +02002074 }
2075 }
2076 return null;
2077 }
2078
Selim Cinek4a1ac842014-05-01 15:51:58 +02002079 /**
Selim Cinek1b2a05e2016-04-28 14:20:39 -07002080 * @return the child before the given view which has visibility unequal to GONE
2081 */
2082 public ExpandableView getViewBeforeView(ExpandableView view) {
2083 ExpandableView previousView = null;
2084 int childCount = getChildCount();
2085 for (int i = 0; i < childCount; i++) {
2086 View child = getChildAt(i);
2087 if (child == view) {
2088 return previousView;
2089 }
2090 if (child.getVisibility() != View.GONE) {
2091 previousView = (ExpandableView) child;
2092 }
2093 }
2094 return null;
2095 }
2096
2097 /**
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002098 * @return The first child which has visibility unequal to GONE which is currently below the
2099 * given translationY or equal to it.
2100 */
Selim Cinekef8c2252017-02-10 14:52:18 -08002101 private View getFirstChildBelowTranlsationY(float translationY, boolean ignoreChildren) {
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002102 int childCount = getChildCount();
2103 for (int i = 0; i < childCount; i++) {
2104 View child = getChildAt(i);
Selim Cinekef8c2252017-02-10 14:52:18 -08002105 if (child.getVisibility() == View.GONE) {
2106 continue;
2107 }
2108 float rowTranslation = child.getTranslationY();
2109 if (rowTranslation >= translationY) {
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002110 return child;
Selim Cinekef8c2252017-02-10 14:52:18 -08002111 } else if (!ignoreChildren && child instanceof ExpandableNotificationRow) {
2112 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2113 if (row.isSummaryWithChildren() && row.areChildrenExpanded()) {
2114 List<ExpandableNotificationRow> notificationChildren =
2115 row.getNotificationChildren();
2116 for (int childIndex = 0; childIndex < notificationChildren.size();
2117 childIndex++) {
2118 ExpandableNotificationRow rowChild = notificationChildren.get(childIndex);
2119 if (rowChild.getTranslationY() + rowTranslation >= translationY) {
2120 return rowChild;
2121 }
2122 }
2123 }
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002124 }
2125 }
2126 return null;
2127 }
2128
2129 /**
Selim Cinek4a1ac842014-05-01 15:51:58 +02002130 * @return the last child which has visibility unequal to GONE
2131 */
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002132 public View getLastChildNotGone() {
Selim Cinek4a1ac842014-05-01 15:51:58 +02002133 int childCount = getChildCount();
2134 for (int i = childCount - 1; i >= 0; i--) {
2135 View child = getChildAt(i);
Selim Cinekdb167372016-11-17 15:41:17 -08002136 if (child.getVisibility() != View.GONE && child != mShelf) {
Selim Cinek4a1ac842014-05-01 15:51:58 +02002137 return child;
2138 }
2139 }
2140 return null;
2141 }
2142
Jorim Jaggi069cd032014-05-15 03:09:01 +02002143 /**
2144 * @return the number of children which have visibility unequal to GONE
2145 */
2146 public int getNotGoneChildCount() {
2147 int childCount = getChildCount();
2148 int count = 0;
2149 for (int i = 0; i < childCount; i++) {
Selim Cinek2cd45df2015-06-09 18:00:07 -07002150 ExpandableView child = (ExpandableView) getChildAt(i);
Selim Cinekdb167372016-11-17 15:41:17 -08002151 if (child.getVisibility() != View.GONE && !child.willBeGone() && child != mShelf) {
Jorim Jaggi069cd032014-05-15 03:09:01 +02002152 count++;
2153 }
2154 }
2155 return count;
2156 }
2157
Selim Cinek67b22602014-03-10 15:40:16 +01002158 private void updateContentHeight() {
2159 int height = 0;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002160 float previousPaddingRequest = mPaddingBetweenElements;
2161 float previousPaddingAmount = 0.0f;
Selim Cinekad7fac02016-10-18 17:09:15 -07002162 int numShownItems = 0;
2163 boolean finish = false;
Lucas Dupin16cfe452018-02-08 13:14:50 -08002164 int maxDisplayedNotifications = mAmbientState.isFullyDark()
Selim Cinekbe2c4432017-05-30 12:11:09 -07002165 ? (hasPulsingNotifications() ? 1 : 0)
Adrian Roos7a9551a2017-01-11 12:27:49 -08002166 : mMaxDisplayedNotifications;
2167
Selim Cinek67b22602014-03-10 15:40:16 +01002168 for (int i = 0; i < getChildCount(); i++) {
Selim Cinek61633a82016-01-25 15:54:10 -08002169 ExpandableView expandableView = (ExpandableView) getChildAt(i);
Lucas Dupin60661a62018-04-12 10:50:13 -07002170 boolean footerViewOnLockScreen = expandableView == mFooterView && onKeyguard();
Selim Cinek281c2022016-10-13 19:14:43 -07002171 if (expandableView.getVisibility() != View.GONE
Lucas Dupin60661a62018-04-12 10:50:13 -07002172 && !expandableView.hasNoContentHeight() && !footerViewOnLockScreen) {
Adrian Roos7d062c42017-03-30 15:11:43 -07002173 boolean limitReached = maxDisplayedNotifications != -1
2174 && numShownItems >= maxDisplayedNotifications;
Lucas Dupin16cfe452018-02-08 13:14:50 -08002175 boolean notificationOnAmbientThatIsNotPulsing = mAmbientState.isFullyDark()
Selim Cinekbe2c4432017-05-30 12:11:09 -07002176 && hasPulsingNotifications()
Adrian Roos7d062c42017-03-30 15:11:43 -07002177 && expandableView instanceof ExpandableNotificationRow
2178 && !isPulsing(((ExpandableNotificationRow) expandableView).getEntry());
2179 if (limitReached || notificationOnAmbientThatIsNotPulsing) {
Selim Cinekad7fac02016-10-18 17:09:15 -07002180 expandableView = mShelf;
2181 finish = true;
2182 }
Selim Cinek42357e02016-02-24 18:48:01 -08002183 float increasedPaddingAmount = expandableView.getIncreasedPaddingAmount();
Selim Cineka7ed2c12017-01-23 20:47:24 -08002184 float padding;
2185 if (increasedPaddingAmount >= 0.0f) {
2186 padding = (int) NotificationUtils.interpolate(
2187 previousPaddingRequest,
2188 mIncreasedPaddingBetweenElements,
2189 increasedPaddingAmount);
2190 previousPaddingRequest = (int) NotificationUtils.interpolate(
Selim Cinek42357e02016-02-24 18:48:01 -08002191 mPaddingBetweenElements,
2192 mIncreasedPaddingBetweenElements,
Selim Cineka7ed2c12017-01-23 20:47:24 -08002193 increasedPaddingAmount);
2194 } else {
2195 int ownPadding = (int) NotificationUtils.interpolate(
2196 0,
2197 mPaddingBetweenElements,
2198 1.0f + increasedPaddingAmount);
2199 if (previousPaddingAmount > 0.0f) {
2200 padding = (int) NotificationUtils.interpolate(
2201 ownPadding,
2202 mIncreasedPaddingBetweenElements,
2203 previousPaddingAmount);
2204 } else {
2205 padding = ownPadding;
2206 }
2207 previousPaddingRequest = ownPadding;
Jorim Jaggid4a57442014-04-10 02:45:55 +02002208 }
Selim Cineka7ed2c12017-01-23 20:47:24 -08002209 if (height != 0) {
2210 height += padding;
2211 }
2212 previousPaddingAmount = increasedPaddingAmount;
Selim Cinek61633a82016-01-25 15:54:10 -08002213 height += expandableView.getIntrinsicHeight();
Selim Cinekad7fac02016-10-18 17:09:15 -07002214 numShownItems++;
2215 if (finish) {
2216 break;
2217 }
Selim Cinek67b22602014-03-10 15:40:16 +01002218 }
2219 }
Lucas Dupin60661a62018-04-12 10:50:13 -07002220 mIntrinsicContentHeight = height;
Selim Cinekf4b04ae2018-06-13 18:23:45 -07002221
2222 // We don't want to use the toppadding since that might be interpolated and we want
2223 // to take the final value of the animation.
2224 int topPadding = mAmbientState.isFullyDark() ? mDarkTopPadding : mRegularTopPadding;
2225 mContentHeight = height + topPadding + mBottomMargin;
Selim Cinekc22fff62016-05-20 12:44:30 -07002226 updateScrollability();
Selim Cinek51d21972017-07-19 17:39:20 -07002227 clampScrollPosition();
Selim Cinek91d4cba2016-11-10 19:59:48 -08002228 mAmbientState.setLayoutMaxHeight(mContentHeight);
Selim Cinekc22fff62016-05-20 12:44:30 -07002229 }
2230
Adrian Roos7d062c42017-03-30 15:11:43 -07002231 private boolean isPulsing(NotificationData.Entry entry) {
Selim Cinekebf42342017-07-13 15:46:10 +02002232 return mAmbientState.isPulsing(entry);
Adrian Roos7d062c42017-03-30 15:11:43 -07002233 }
2234
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09002235 @Override
Selim Cinekbe2c4432017-05-30 12:11:09 -07002236 public boolean hasPulsingNotifications() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +09002237 return mPulsing;
Adrian Roos7d062c42017-03-30 15:11:43 -07002238 }
2239
Selim Cinekc22fff62016-05-20 12:44:30 -07002240 private void updateScrollability() {
Riddle Hsu065c01c2018-05-10 23:14:19 +08002241 boolean scrollable = !mQsExpanded && getScrollRange() > 0;
Selim Cinekc22fff62016-05-20 12:44:30 -07002242 if (scrollable != mScrollable) {
2243 mScrollable = scrollable;
2244 setFocusable(scrollable);
Selim Cinekef406062016-09-29 17:33:13 -07002245 updateForwardAndBackwardScrollability();
2246 }
2247 }
2248
2249 private void updateForwardAndBackwardScrollability() {
2250 boolean forwardScrollable = mScrollable && mOwnScrollY < getScrollRange();
2251 boolean backwardsScrollable = mScrollable && mOwnScrollY > 0;
2252 boolean changed = forwardScrollable != mForwardScrollable
2253 || backwardsScrollable != mBackwardScrollable;
2254 mForwardScrollable = forwardScrollable;
2255 mBackwardScrollable = backwardsScrollable;
2256 if (changed) {
2257 sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
Selim Cinekc22fff62016-05-20 12:44:30 -07002258 }
Selim Cinek67b22602014-03-10 15:40:16 +01002259 }
2260
Selim Cinek6811d722016-01-19 17:53:12 -08002261 private void updateBackground() {
Anthony Chen3cb3ad92016-12-01 10:58:47 -08002262 // No need to update the background color if it's not being drawn.
Lucas Dupin16cfe452018-02-08 13:14:50 -08002263 if (!mShouldDrawNotificationBackground || mAmbientState.isFullyDark()) {
Selim Cinek6811d722016-01-19 17:53:12 -08002264 return;
2265 }
Anthony Chen3cb3ad92016-12-01 10:58:47 -08002266
Selim Cinek6811d722016-01-19 17:53:12 -08002267 updateBackgroundBounds();
2268 if (!mCurrentBounds.equals(mBackgroundBounds)) {
Selim Cinek54680902016-10-19 16:49:44 -07002269 boolean animate = mAnimateNextBackgroundTop || mAnimateNextBackgroundBottom
2270 || areBoundsAnimating();
2271 if (!isExpanded()) {
2272 abortBackgroundAnimators();
2273 animate = false;
2274 }
2275 if (animate) {
Selim Cinek614576e2016-01-20 10:54:09 -08002276 startBackgroundAnimation();
2277 } else {
2278 mCurrentBounds.set(mBackgroundBounds);
2279 applyCurrentBackgroundBounds();
2280 }
2281 } else {
Selim Cinek54680902016-10-19 16:49:44 -07002282 abortBackgroundAnimators();
Selim Cinek6811d722016-01-19 17:53:12 -08002283 }
Selim Cinek614576e2016-01-20 10:54:09 -08002284 mAnimateNextBackgroundBottom = false;
2285 mAnimateNextBackgroundTop = false;
2286 }
2287
Selim Cinek54680902016-10-19 16:49:44 -07002288 private void abortBackgroundAnimators() {
2289 if (mBottomAnimator != null) {
2290 mBottomAnimator.cancel();
2291 }
2292 if (mTopAnimator != null) {
2293 mTopAnimator.cancel();
2294 }
2295 }
2296
Selim Cinek614576e2016-01-20 10:54:09 -08002297 private boolean areBoundsAnimating() {
2298 return mBottomAnimator != null || mTopAnimator != null;
2299 }
2300
2301 private void startBackgroundAnimation() {
Selim Cinek01e40192016-05-12 14:57:22 -07002302 // left and right are always instantly applied
2303 mCurrentBounds.left = mBackgroundBounds.left;
2304 mCurrentBounds.right = mBackgroundBounds.right;
Selim Cinek614576e2016-01-20 10:54:09 -08002305 startBottomAnimation();
2306 startTopAnimation();
2307 }
2308
2309 private void startTopAnimation() {
2310 int previousEndValue = mEndAnimationRect.top;
2311 int newEndValue = mBackgroundBounds.top;
2312 ObjectAnimator previousAnimator = mTopAnimator;
2313 if (previousAnimator != null && previousEndValue == newEndValue) {
2314 return;
2315 }
2316 if (!mAnimateNextBackgroundTop) {
2317 // just a local update was performed
2318 if (previousAnimator != null) {
2319 // we need to increase all animation keyframes of the previous animator by the
2320 // relative change to the end value
2321 int previousStartValue = mStartAnimationRect.top;
2322 PropertyValuesHolder[] values = previousAnimator.getValues();
2323 values[0].setIntValues(previousStartValue, newEndValue);
2324 mStartAnimationRect.top = previousStartValue;
2325 mEndAnimationRect.top = newEndValue;
2326 previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
2327 return;
2328 } else {
2329 // no new animation needed, let's just apply the value
2330 setBackgroundTop(newEndValue);
2331 return;
2332 }
2333 }
2334 if (previousAnimator != null) {
2335 previousAnimator.cancel();
2336 }
2337 ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop",
2338 mCurrentBounds.top, newEndValue);
2339 Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
2340 animator.setInterpolator(interpolator);
2341 animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
2342 // remove the tag when the animation is finished
2343 animator.addListener(new AnimatorListenerAdapter() {
2344 @Override
2345 public void onAnimationEnd(Animator animation) {
2346 mStartAnimationRect.top = -1;
2347 mEndAnimationRect.top = -1;
2348 mTopAnimator = null;
2349 }
2350 });
2351 animator.start();
2352 mStartAnimationRect.top = mCurrentBounds.top;
2353 mEndAnimationRect.top = newEndValue;
2354 mTopAnimator = animator;
2355 }
2356
2357 private void startBottomAnimation() {
2358 int previousStartValue = mStartAnimationRect.bottom;
2359 int previousEndValue = mEndAnimationRect.bottom;
2360 int newEndValue = mBackgroundBounds.bottom;
2361 ObjectAnimator previousAnimator = mBottomAnimator;
2362 if (previousAnimator != null && previousEndValue == newEndValue) {
2363 return;
2364 }
2365 if (!mAnimateNextBackgroundBottom) {
2366 // just a local update was performed
2367 if (previousAnimator != null) {
2368 // we need to increase all animation keyframes of the previous animator by the
2369 // relative change to the end value
2370 PropertyValuesHolder[] values = previousAnimator.getValues();
2371 values[0].setIntValues(previousStartValue, newEndValue);
2372 mStartAnimationRect.bottom = previousStartValue;
2373 mEndAnimationRect.bottom = newEndValue;
2374 previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
2375 return;
2376 } else {
2377 // no new animation needed, let's just apply the value
2378 setBackgroundBottom(newEndValue);
2379 return;
2380 }
2381 }
2382 if (previousAnimator != null) {
2383 previousAnimator.cancel();
2384 }
2385 ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom",
2386 mCurrentBounds.bottom, newEndValue);
2387 Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
2388 animator.setInterpolator(interpolator);
2389 animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
2390 // remove the tag when the animation is finished
2391 animator.addListener(new AnimatorListenerAdapter() {
2392 @Override
2393 public void onAnimationEnd(Animator animation) {
2394 mStartAnimationRect.bottom = -1;
2395 mEndAnimationRect.bottom = -1;
2396 mBottomAnimator = null;
2397 }
2398 });
2399 animator.start();
2400 mStartAnimationRect.bottom = mCurrentBounds.bottom;
2401 mEndAnimationRect.bottom = newEndValue;
2402 mBottomAnimator = animator;
2403 }
2404
2405 private void setBackgroundTop(int top) {
2406 mCurrentBounds.top = top;
2407 applyCurrentBackgroundBounds();
2408 }
2409
2410 public void setBackgroundBottom(int bottom) {
2411 mCurrentBounds.bottom = bottom;
2412 applyCurrentBackgroundBounds();
2413 }
2414
2415 private void applyCurrentBackgroundBounds() {
Anthony Chen3cb3ad92016-12-01 10:58:47 -08002416 // If the background of the notification is not being drawn, then there is no need to
2417 // exclude an area in the scrim. Rather, the scrim's color should serve as the background.
2418 if (!mShouldDrawNotificationBackground) {
2419 return;
2420 }
2421
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02002422 final boolean awake = mInterpolatedDarkAmount != 0 || mAmbientState.isDark();
Selim Cinek9bfba9c2016-08-08 15:20:06 -07002423 mScrimController.setExcludedBackgroundArea(
Lucas Dupin8e9fa2d2018-01-29 15:36:35 -08002424 mFadingOut || mParentNotFullyVisible || awake || mIsClipped ? null
Selim Cinek9bfba9c2016-08-08 15:20:06 -07002425 : mCurrentBounds);
Selim Cinek614576e2016-01-20 10:54:09 -08002426 invalidate();
Selim Cinek6811d722016-01-19 17:53:12 -08002427 }
2428
2429 /**
2430 * Update the background bounds to the new desired bounds
2431 */
2432 private void updateBackgroundBounds() {
shawnlin3a2a2e22018-05-04 17:09:50 +08002433 getLocationInWindow(mTempInt2);
2434 mBackgroundBounds.left = mTempInt2[0] + mSidePaddings;
2435 mBackgroundBounds.right = mTempInt2[0] + getWidth() - mSidePaddings;
2436
Selim Cinek614576e2016-01-20 10:54:09 -08002437 if (!mIsExpanded) {
2438 mBackgroundBounds.top = 0;
2439 mBackgroundBounds.bottom = 0;
Selim Cinek1791f502016-10-07 17:38:03 -04002440 return;
Selim Cinek614576e2016-01-20 10:54:09 -08002441 }
2442 ActivatableNotificationView firstView = mFirstVisibleBackgroundChild;
Selim Cinek6811d722016-01-19 17:53:12 -08002443 int top = 0;
2444 if (firstView != null) {
Lucas Dupin4f67be72017-05-29 11:30:29 -07002445 // Round Y up to avoid seeing the background during animation
2446 int finalTranslationY = (int) Math.ceil(ViewState.getFinalTranslationY(firstView));
Selim Cinek614576e2016-01-20 10:54:09 -08002447 if (mAnimateNextBackgroundTop
2448 || mTopAnimator == null && mCurrentBounds.top == finalTranslationY
2449 || mTopAnimator != null && mEndAnimationRect.top == finalTranslationY) {
Selim Cinek6811d722016-01-19 17:53:12 -08002450 // we're ending up at the same location as we are now, lets just skip the animation
2451 top = finalTranslationY;
2452 } else {
Lucas Dupin4f67be72017-05-29 11:30:29 -07002453 top = (int) Math.ceil(firstView.getTranslationY());
Selim Cinek6811d722016-01-19 17:53:12 -08002454 }
2455 }
Anthony Chen9e05d462017-04-07 10:10:21 -07002456 ActivatableNotificationView lastView =
2457 mShelf.hasItemsInStableShelf() && mShelf.getVisibility() != GONE
2458 ? mShelf
2459 : mLastVisibleBackgroundChild;
2460 int bottom;
Selim Cinek6811d722016-01-19 17:53:12 -08002461 if (lastView != null) {
Selim Cinekeccb5de2016-10-28 15:04:05 -07002462 int finalTranslationY;
2463 if (lastView == mShelf) {
2464 finalTranslationY = (int) mShelf.getTranslationY();
2465 } else {
2466 finalTranslationY = (int) ViewState.getFinalTranslationY(lastView);
2467 }
Selim Cinek0cfbef42016-11-09 19:06:36 -08002468 int finalHeight = ExpandableViewState.getFinalActualHeight(lastView);
Selim Cinekc519dcf2016-11-22 13:45:39 -08002469 int finalBottom = finalTranslationY + finalHeight - lastView.getClipBottomAmount();
Selim Cinek614576e2016-01-20 10:54:09 -08002470 if (mAnimateNextBackgroundBottom
2471 || mBottomAnimator == null && mCurrentBounds.bottom == finalBottom
2472 || mBottomAnimator != null && mEndAnimationRect.bottom == finalBottom) {
Selim Cinek6811d722016-01-19 17:53:12 -08002473 // we're ending up at the same location as we are now, lets just skip the animation
2474 bottom = finalBottom;
2475 } else {
Selim Cinekc519dcf2016-11-22 13:45:39 -08002476 bottom = (int) (lastView.getTranslationY() + lastView.getActualHeight()
2477 - lastView.getClipBottomAmount());
Selim Cinek6811d722016-01-19 17:53:12 -08002478 }
Selim Cinek3776fe02016-02-04 13:32:43 -08002479 } else {
Selim Cinekd393d5c2016-08-03 16:18:12 -07002480 top = mTopPadding;
Selim Cinek7db42982016-02-02 15:21:41 -08002481 bottom = top;
Selim Cinek6811d722016-01-19 17:53:12 -08002482 }
Selim Cinek355652a2016-12-07 13:32:12 -08002483 if (mStatusBarState != StatusBarState.KEYGUARD) {
Selim Cinekd381bc32016-08-15 12:40:57 -07002484 top = (int) Math.max(mTopPadding + mStackTranslation, top);
Selim Cinek3776fe02016-02-04 13:32:43 -08002485 } else {
2486 // otherwise the animation from the shade to the keyguard will jump as it's maxed
Selim Cinekd381bc32016-08-15 12:40:57 -07002487 top = Math.max(0, top);
Selim Cinek3776fe02016-02-04 13:32:43 -08002488 }
Selim Cinekd381bc32016-08-15 12:40:57 -07002489 mBackgroundBounds.top = top;
shawnlinc3457912018-05-15 16:39:56 +08002490 mBackgroundBounds.bottom = Math.max(bottom, top);
Selim Cinek6811d722016-01-19 17:53:12 -08002491 }
2492
Selim Cinek614576e2016-01-20 10:54:09 -08002493 private ActivatableNotificationView getFirstPinnedHeadsUp() {
2494 int childCount = getChildCount();
2495 for (int i = 0; i < childCount; i++) {
2496 View child = getChildAt(i);
2497 if (child.getVisibility() != View.GONE
2498 && child instanceof ExpandableNotificationRow) {
2499 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2500 if (row.isPinned()) {
2501 return row;
2502 }
2503 }
2504 }
2505 return null;
2506 }
2507
2508 private ActivatableNotificationView getLastChildWithBackground() {
Selim Cinek6811d722016-01-19 17:53:12 -08002509 int childCount = getChildCount();
2510 for (int i = childCount - 1; i >= 0; i--) {
2511 View child = getChildAt(i);
Selim Cinek48ff9b42016-11-09 19:31:51 -08002512 if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView
2513 && child != mShelf) {
Selim Cinek6811d722016-01-19 17:53:12 -08002514 return (ActivatableNotificationView) child;
2515 }
2516 }
2517 return null;
2518 }
2519
Selim Cinek614576e2016-01-20 10:54:09 -08002520 private ActivatableNotificationView getFirstChildWithBackground() {
Selim Cinek6811d722016-01-19 17:53:12 -08002521 int childCount = getChildCount();
2522 for (int i = 0; i < childCount; i++) {
2523 View child = getChildAt(i);
Selim Cinek48ff9b42016-11-09 19:31:51 -08002524 if (child.getVisibility() != View.GONE && child instanceof ActivatableNotificationView
2525 && child != mShelf) {
Selim Cinek6811d722016-01-19 17:53:12 -08002526 return (ActivatableNotificationView) child;
2527 }
2528 }
2529 return null;
2530 }
2531
Selim Cinek67b22602014-03-10 15:40:16 +01002532 /**
2533 * Fling the scroll view
2534 *
2535 * @param velocityY The initial velocity in the Y direction. Positive
2536 * numbers mean that the finger/cursor is moving down the screen,
2537 * which means we want to scroll towards the top.
2538 */
Muyuan Li26e30ae2016-04-11 17:31:42 -07002539 protected void fling(int velocityY) {
Selim Cinek67b22602014-03-10 15:40:16 +01002540 if (getChildCount() > 0) {
Selim Cinek4195dd02014-05-19 18:16:14 +02002541 int scrollRange = getScrollRange();
Selim Cinek67b22602014-03-10 15:40:16 +01002542
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002543 float topAmount = getCurrentOverScrollAmount(true);
2544 float bottomAmount = getCurrentOverScrollAmount(false);
2545 if (velocityY < 0 && topAmount > 0) {
Selim Cinekef406062016-09-29 17:33:13 -07002546 setOwnScrollY(mOwnScrollY - (int) topAmount);
Selim Cinek1408eb52014-06-02 14:45:38 +02002547 mDontReportNextOverScroll = true;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002548 setOverScrollAmount(0, true, false);
Selim Cinekfed1ab62014-06-17 14:10:33 -07002549 mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */)
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002550 * mOverflingDistance + topAmount;
2551 } else if (velocityY > 0 && bottomAmount > 0) {
Selim Cinekef406062016-09-29 17:33:13 -07002552 setOwnScrollY((int) (mOwnScrollY + bottomAmount));
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002553 setOverScrollAmount(0, false, false);
Selim Cinekfed1ab62014-06-17 14:10:33 -07002554 mMaxOverScroll = Math.abs(velocityY) / 1000f
2555 * getRubberBandFactor(false /* onTop */) * mOverflingDistance
2556 + bottomAmount;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002557 } else {
2558 // it will be set once we reach the boundary
2559 mMaxOverScroll = 0.0f;
2560 }
Selim Cinek94ab18c2016-02-25 12:35:51 -08002561 int minScrollY = Math.max(0, scrollRange);
2562 if (mExpandedInThisMotion) {
2563 minScrollY = Math.min(minScrollY, mMaxScrollAfterExpand);
2564 }
Selim Cinek9212de82017-02-06 16:04:28 -08002565 mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, minScrollY, 0,
2566 mExpandedInThisMotion && mOwnScrollY >= 0 ? 0 : Integer.MAX_VALUE / 2);
Selim Cinek67b22602014-03-10 15:40:16 +01002567
Selim Cinek9212de82017-02-06 16:04:28 -08002568 animateScroll();
Selim Cinek67b22602014-03-10 15:40:16 +01002569 }
2570 }
2571
Selim Cinek1408eb52014-06-02 14:45:38 +02002572 /**
2573 * @return Whether a fling performed on the top overscroll edge lead to the expanded
2574 * overScroll view (i.e QS).
2575 */
2576 private boolean shouldOverScrollFling(int initialVelocity) {
2577 float topOverScroll = getCurrentOverScrollAmount(true);
2578 return mScrolledToTopOnFirstDown
2579 && !mExpandedInThisMotion
2580 && topOverScroll > mMinTopOverScrollToEscape
2581 && initialVelocity > 0;
2582 }
2583
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01002584 /**
2585 * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into
2586 * account.
2587 *
2588 * @param qsHeight the top padding imposed by the quick settings panel
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01002589 * @param animate whether to animate the change
2590 * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and
2591 * {@code qsHeight} is the final top padding
2592 */
Jason Monk16ac3772016-02-10 15:39:21 -05002593 public void updateTopPadding(float qsHeight, boolean animate,
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01002594 boolean ignoreIntrinsicPadding) {
Selim Cinekbc243a92016-09-27 16:35:13 -07002595 int topPadding = (int) qsHeight;
Selim Cinekd1ad9ab2016-03-01 17:52:20 -08002596 int minStackHeight = getLayoutMinHeight();
Selim Cinekbc243a92016-09-27 16:35:13 -07002597 if (topPadding + minStackHeight > getHeight()) {
2598 mTopPaddingOverflow = topPadding + minStackHeight - getHeight();
Selim Cinek1408eb52014-06-02 14:45:38 +02002599 } else {
Jorim Jaggi30c305c2014-07-01 23:34:41 +02002600 mTopPaddingOverflow = 0;
Selim Cinek1408eb52014-06-02 14:45:38 +02002601 }
Selim Cinekbc243a92016-09-27 16:35:13 -07002602 setTopPadding(ignoreIntrinsicPadding ? topPadding : clampPadding(topPadding),
Jorim Jaggi06a0c3a2014-10-29 17:17:21 +01002603 animate);
Selim Cinekbc243a92016-09-27 16:35:13 -07002604 setExpandedHeight(mExpandedHeight);
Selim Cinek1408eb52014-06-02 14:45:38 +02002605 }
2606
shawnlin8e4e92c2018-04-12 18:47:24 +08002607 public void setMaxTopPadding(int maxTopPadding) {
2608 mMaxTopPadding = maxTopPadding;
2609 }
2610
Selim Cinekd1ad9ab2016-03-01 17:52:20 -08002611 public int getLayoutMinHeight() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08002612 if (isHeadsUpTransition()) {
2613 return getTopHeadsUpPinnedHeight();
2614 }
Anthony Chen9e05d462017-04-07 10:10:21 -07002615 return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight();
Selim Cinek94c2d822016-07-13 18:50:04 -07002616 }
2617
Julia Reynolds34f14962018-05-03 12:40:20 +00002618 public int getFirstChildIntrinsicHeight() {
2619 final ExpandableView firstChild = getFirstChildNotGone();
2620 int firstChildMinHeight = firstChild != null
2621 ? firstChild.getIntrinsicHeight()
2622 : mEmptyShadeView != null
2623 ? mEmptyShadeView.getIntrinsicHeight()
2624 : mCollapsedSize;
2625 if (mOwnScrollY > 0) {
2626 firstChildMinHeight = Math.max(firstChildMinHeight - mOwnScrollY, mCollapsedSize);
2627 }
2628 return firstChildMinHeight;
2629 }
2630
Jorim Jaggi30c305c2014-07-01 23:34:41 +02002631 public float getTopPaddingOverflow() {
2632 return mTopPaddingOverflow;
2633 }
2634
Jorim Jaggi2580a9762014-06-25 03:08:25 +02002635 public int getPeekHeight() {
Selim Cinek816c8e42015-11-19 12:00:45 -08002636 final ExpandableView firstChild = getFirstChildNotGone();
Selim Cinek567e8452016-03-24 10:54:56 -07002637 final int firstChildMinHeight = firstChild != null ? firstChild.getCollapsedHeight()
Selim Cinek816c8e42015-11-19 12:00:45 -08002638 : mCollapsedSize;
Selim Cinekdb167372016-11-17 15:41:17 -08002639 int shelfHeight = 0;
Anthony Chen9e05d462017-04-07 10:10:21 -07002640 if (mLastVisibleBackgroundChild != null && mShelf.getVisibility() != GONE) {
Selim Cinekdb167372016-11-17 15:41:17 -08002641 shelfHeight = mShelf.getIntrinsicHeight();
2642 }
2643 return mIntrinsicPadding + firstChildMinHeight + shelfHeight;
Jorim Jaggi2580a9762014-06-25 03:08:25 +02002644 }
2645
Selim Cinek1408eb52014-06-02 14:45:38 +02002646 private int clampPadding(int desiredPadding) {
2647 return Math.max(desiredPadding, mIntrinsicPadding);
2648 }
2649
Selim Cinekfed1ab62014-06-17 14:10:33 -07002650 private float getRubberBandFactor(boolean onTop) {
2651 if (!onTop) {
2652 return RUBBER_BAND_FACTOR_NORMAL;
2653 }
Jorim Jaggi47c85a32014-06-05 17:25:40 +02002654 if (mExpandedInThisMotion) {
2655 return RUBBER_BAND_FACTOR_AFTER_EXPAND;
Jorim Jaggie4b840d2015-06-30 16:19:17 -07002656 } else if (mIsExpansionChanging || mPanelTracking) {
Jorim Jaggi47c85a32014-06-05 17:25:40 +02002657 return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND;
2658 } else if (mScrolledToTopOnFirstDown) {
2659 return 1.0f;
2660 }
2661 return RUBBER_BAND_FACTOR_NORMAL;
Selim Cinek1408eb52014-06-02 14:45:38 +02002662 }
2663
Jorim Jaggi475b21d2014-07-01 18:13:24 +02002664 /**
2665 * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is
2666 * rubberbanded, false if it is technically an overscroll but rather a motion to expand the
2667 * overscroll view (e.g. expand QS).
2668 */
2669 private boolean isRubberbanded(boolean onTop) {
Jorim Jaggie4b840d2015-06-30 16:19:17 -07002670 return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking
Jorim Jaggi475b21d2014-07-01 18:13:24 +02002671 || !mScrolledToTopOnFirstDown;
2672 }
2673
Selim Cinek67b22602014-03-10 15:40:16 +01002674 private void endDrag() {
2675 setIsBeingDragged(false);
2676
2677 recycleVelocityTracker();
2678
Selim Cinek8d9ff9c2014-05-12 15:13:04 +02002679 if (getCurrentOverScrollAmount(true /* onTop */) > 0) {
2680 setOverScrollAmount(0, true /* onTop */, true /* animate */);
2681 }
2682 if (getCurrentOverScrollAmount(false /* onTop */) > 0) {
2683 setOverScrollAmount(0, false /* onTop */, true /* animate */);
2684 }
Selim Cinek67b22602014-03-10 15:40:16 +01002685 }
2686
Jorim Jaggi56306252014-07-03 00:40:09 +02002687 private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) {
2688 ev.offsetLocation(sourceView.getX(), sourceView.getY());
2689 ev.offsetLocation(-targetView.getX(), -targetView.getY());
2690 }
2691
Selim Cinek67b22602014-03-10 15:40:16 +01002692 @Override
2693 public boolean onInterceptTouchEvent(MotionEvent ev) {
Selim Cinek1408eb52014-06-02 14:45:38 +02002694 initDownStates(ev);
Selim Cinek3a9c10a2014-10-28 14:21:10 +01002695 handleEmptySpaceClick(ev);
Selim Cinek1408eb52014-06-02 14:45:38 +02002696 boolean expandWantsIt = false;
Selim Cinekcb9400a2015-06-03 16:56:13 +02002697 if (!mSwipingInProgress && !mOnlyScrollingInThisMotion) {
Selim Cinek1408eb52014-06-02 14:45:38 +02002698 expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev);
2699 }
Selim Cinek67b22602014-03-10 15:40:16 +01002700 boolean scrollWantsIt = false;
Selim Cinek1408eb52014-06-02 14:45:38 +02002701 if (!mSwipingInProgress && !mExpandingNotification) {
Selim Cinek67b22602014-03-10 15:40:16 +01002702 scrollWantsIt = onInterceptTouchEventScroll(ev);
2703 }
2704 boolean swipeWantsIt = false;
Selim Cinek1408eb52014-06-02 14:45:38 +02002705 if (!mIsBeingDragged
2706 && !mExpandingNotification
2707 && !mExpandedInThisMotion
Adrian Roosfa139752016-04-27 09:59:08 -07002708 && !mOnlyScrollingInThisMotion
2709 && !mDisallowDismissInThisMotion) {
Selim Cinek67b22602014-03-10 15:40:16 +01002710 swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev);
2711 }
Mady Mellorc2dbe492017-03-30 13:22:03 -07002712 // Check if we need to clear any snooze leavebehinds
2713 boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP;
Eliot Courtney47098cb2017-10-18 17:30:30 +09002714 NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts();
Mady Mellorc2dbe492017-03-30 13:22:03 -07002715 if (!isTouchInView(ev, guts) && isUp && !swipeWantsIt && !expandWantsIt
2716 && !scrollWantsIt) {
2717 mCheckForLeavebehind = false;
Eliot Courtney47098cb2017-10-18 17:30:30 +09002718 mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */,
2719 false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */,
2720 false /* resetMenu */);
Mady Mellorc2dbe492017-03-30 13:22:03 -07002721 }
2722 if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
2723 mCheckForLeavebehind = true;
2724 }
Selim Cinek1408eb52014-06-02 14:45:38 +02002725 return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev);
2726 }
2727
Selim Cinek3a9c10a2014-10-28 14:21:10 +01002728 private void handleEmptySpaceClick(MotionEvent ev) {
2729 switch (ev.getActionMasked()) {
2730 case MotionEvent.ACTION_MOVE:
2731 if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop
2732 || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop )) {
2733 mTouchIsClick = false;
2734 }
2735 break;
2736 case MotionEvent.ACTION_UP:
Selim Cinek355652a2016-12-07 13:32:12 -08002737 if (mStatusBarState != StatusBarState.KEYGUARD && mTouchIsClick &&
Selim Cinek3a9c10a2014-10-28 14:21:10 +01002738 isBelowLastNotification(mInitialTouchX, mInitialTouchY)) {
2739 mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY);
2740 }
2741 break;
2742 }
2743 }
2744
Selim Cinek1408eb52014-06-02 14:45:38 +02002745 private void initDownStates(MotionEvent ev) {
2746 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
2747 mExpandedInThisMotion = false;
2748 mOnlyScrollingInThisMotion = !mScroller.isFinished();
Selim Cinekf7a14c02014-07-07 14:01:46 +02002749 mDisallowScrollingInThisMotion = false;
Adrian Roosfa139752016-04-27 09:59:08 -07002750 mDisallowDismissInThisMotion = false;
Selim Cinek3a9c10a2014-10-28 14:21:10 +01002751 mTouchIsClick = true;
2752 mInitialTouchX = ev.getX();
2753 mInitialTouchY = ev.getY();
Selim Cinek1408eb52014-06-02 14:45:38 +02002754 }
Selim Cinek67b22602014-03-10 15:40:16 +01002755 }
2756
Selim Cinekef5127e2015-12-21 16:55:58 -08002757 public void setChildTransferInProgress(boolean childTransferInProgress) {
2758 mChildTransferInProgress = childTransferInProgress;
2759 }
2760
Christoph Studer068f5922014-04-08 17:43:07 -04002761 @Override
Adam Powell6690d012015-06-17 16:41:56 -07002762 public void onViewRemoved(View child) {
Christoph Studer068f5922014-04-08 17:43:07 -04002763 super.onViewRemoved(child);
Selim Cinekb5605e52015-02-20 18:21:41 +01002764 // we only call our internal methods if this is actually a removal and not just a
2765 // notification which becomes a child notification
Selim Cinekef5127e2015-12-21 16:55:58 -08002766 if (!mChildTransferInProgress) {
Selim Cinekd1395642016-04-28 12:22:42 -07002767 onViewRemovedInternal(child, this);
Selim Cinekb5605e52015-02-20 18:21:41 +01002768 }
2769 }
2770
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09002771 @Override
Mady Mellor4c97b0a2017-02-15 11:16:13 -08002772 public void cleanUpViewState(View child) {
2773 if (child == mTranslatingParentView) {
2774 mTranslatingParentView = null;
2775 }
2776 mCurrentStackScrollState.removeViewStateForView(child);
2777 }
2778
Selim Cinek197823d2016-03-24 13:06:00 -07002779 @Override
2780 public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
2781 super.requestDisallowInterceptTouchEvent(disallowIntercept);
2782 if (disallowIntercept) {
Geoffrey Pitsch409db272017-08-28 14:51:52 +00002783 cancelLongPress();
Selim Cinek197823d2016-03-24 13:06:00 -07002784 }
2785 }
2786
Selim Cineka5703182016-05-11 21:23:16 -04002787 private void onViewRemovedInternal(View child, ViewGroup container) {
Selim Cinek159ffdb2014-06-04 22:24:18 +02002788 if (mChangePositionInProgress) {
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002789 // This is only a position change, don't do anything special
2790 return;
2791 }
Selim Cinekd1395642016-04-28 12:22:42 -07002792 ExpandableView expandableView = (ExpandableView) child;
2793 expandableView.setOnHeightChangedListener(null);
Christoph Studer068f5922014-04-08 17:43:07 -04002794 mCurrentStackScrollState.removeViewStateForView(child);
Selim Cinekd1395642016-04-28 12:22:42 -07002795 updateScrollStateForRemovedChild(expandableView);
Selim Cinek2aab2fb2015-04-15 18:47:01 -07002796 boolean animationGenerated = generateRemoveAnimation(child);
Selim Cinekd1395642016-04-28 12:22:42 -07002797 if (animationGenerated) {
Rohan Shah524cf7b2018-03-15 14:40:02 -07002798 if (!mSwipedOutViews.contains(child)
2799 || Math.abs(expandableView.getTranslation()) != expandableView.getWidth()) {
Selim Cineka5703182016-05-11 21:23:16 -04002800 container.addTransientView(child, 0);
2801 expandableView.setTransientContainer(container);
Selim Cinekd1395642016-04-28 12:22:42 -07002802 }
2803 } else {
2804 mSwipedOutViews.remove(child);
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002805 }
Selim Cinekcab4a602014-09-03 14:47:57 +02002806 updateAnimationState(false, child);
Selim Cinekc0f4c012014-08-25 15:45:33 +02002807
Selim Cineke9bad242016-06-15 11:46:37 -07002808 focusNextViewIfFocused(child);
2809 }
2810
2811 private void focusNextViewIfFocused(View view) {
2812 if (view instanceof ExpandableNotificationRow) {
2813 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
2814 if (row.shouldRefocusOnDismiss()) {
2815 View nextView = row.getChildAfterViewWhenDismissed();
2816 if (nextView == null) {
2817 View groupParentWhenDismissed = row.getGroupParentWhenDismissed();
2818 nextView = getFirstChildBelowTranlsationY(groupParentWhenDismissed != null
2819 ? groupParentWhenDismissed.getTranslationY()
Selim Cinekef8c2252017-02-10 14:52:18 -08002820 : view.getTranslationY(), true /* ignoreChildren */);
Selim Cineke9bad242016-06-15 11:46:37 -07002821 }
2822 if (nextView != null) {
2823 nextView.requestAccessibilityFocus();
2824 }
2825 }
2826 }
2827
Selim Cinekc27437b2014-05-14 10:23:33 +02002828 }
2829
Selim Cinekb5605e52015-02-20 18:21:41 +01002830 private boolean isChildInGroup(View child) {
2831 return child instanceof ExpandableNotificationRow
2832 && mGroupManager.isChildInGroupWithSummary(
2833 ((ExpandableNotificationRow) child).getStatusBarNotification());
2834 }
2835
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002836 /**
2837 * Generate a remove animation for a child view.
2838 *
2839 * @param child The view to generate the remove animation for.
2840 * @return Whether an animation was generated.
2841 */
2842 private boolean generateRemoveAnimation(View child) {
Selim Cineke0890e52015-06-17 11:17:08 -07002843 if (removeRemovedChildFromHeadsUpChangeAnimations(child)) {
Selim Cinek233241f2015-06-01 06:11:19 -07002844 mAddedHeadsUpChildren.remove(child);
2845 return false;
2846 }
Selim Cinek0fccc722015-07-29 17:04:36 -07002847 if (isClickedHeadsUp(child)) {
Selim Cinek9dd0d042018-05-14 18:12:42 -07002848 // An animation is already running, add it transiently
2849 mClearTransientViewsWhenFinished.add((ExpandableView) child);
Selim Cinek0fccc722015-07-29 17:04:36 -07002850 return true;
2851 }
Selim Cinekb5605e52015-02-20 18:21:41 +01002852 if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) {
Selim Cinek233241f2015-06-01 06:11:19 -07002853 if (!mChildrenToAddAnimated.contains(child)) {
Selim Cinekf4c19962014-05-01 21:55:31 +02002854 // Generate Animations
2855 mChildrenToRemoveAnimated.add(child);
Jorim Jaggi0dd68812014-05-01 19:17:37 +02002856 mNeedsAnimation = true;
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002857 return true;
Selim Cinekf4c19962014-05-01 21:55:31 +02002858 } else {
2859 mChildrenToAddAnimated.remove(child);
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02002860 mFromMoreCardAdditions.remove(child);
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002861 return false;
Selim Cinekf4c19962014-05-01 21:55:31 +02002862 }
Selim Cinek572bbd42014-04-25 16:43:27 +02002863 }
Selim Cinek8efa6dd2014-05-19 16:27:37 +02002864 return false;
Selim Cinek572bbd42014-04-25 16:43:27 +02002865 }
2866
Selim Cinek0fccc722015-07-29 17:04:36 -07002867 private boolean isClickedHeadsUp(View child) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +09002868 return HeadsUpUtil.isClickedHeadsUpNotification(child);
Selim Cinek0fccc722015-07-29 17:04:36 -07002869 }
2870
Selim Cineke0890e52015-06-17 11:17:08 -07002871 /**
2872 * Remove a removed child view from the heads up animations if it was just added there
2873 *
2874 * @return whether any child was removed from the list to animate
2875 */
2876 private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) {
2877 boolean hasAddEvent = false;
Selim Cinekffa6eb82015-05-21 12:11:12 -07002878 for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) {
2879 ExpandableNotificationRow row = eventPair.first;
Selim Cineke0890e52015-06-17 11:17:08 -07002880 boolean isHeadsUp = eventPair.second;
Selim Cinekffa6eb82015-05-21 12:11:12 -07002881 if (child == row) {
Selim Cineke0890e52015-06-17 11:17:08 -07002882 mTmpList.add(eventPair);
2883 hasAddEvent |= isHeadsUp;
Selim Cinekffa6eb82015-05-21 12:11:12 -07002884 }
2885 }
Selim Cineke0890e52015-06-17 11:17:08 -07002886 if (hasAddEvent) {
2887 // This child was just added lets remove all events.
2888 mHeadsUpChangeAnimations.removeAll(mTmpList);
Selim Cinekcafa87f2016-10-26 17:00:17 -07002889 ((ExpandableNotificationRow ) child).setHeadsUpAnimatingAway(false);
Selim Cineke0890e52015-06-17 11:17:08 -07002890 }
2891 mTmpList.clear();
2892 return hasAddEvent;
Selim Cinekffa6eb82015-05-21 12:11:12 -07002893 }
2894
Selim Cinek572bbd42014-04-25 16:43:27 +02002895 /**
Selim Cinekb5605e52015-02-20 18:21:41 +01002896 * @param child the child to query
2897 * @return whether a view is not a top level child but a child notification and that group is
2898 * not expanded
2899 */
2900 private boolean isChildInInvisibleGroup(View child) {
2901 if (child instanceof ExpandableNotificationRow) {
2902 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
2903 ExpandableNotificationRow groupSummary =
2904 mGroupManager.getGroupSummary(row.getStatusBarNotification());
2905 if (groupSummary != null && groupSummary != row) {
Selim Cinek83bc7832015-10-22 13:26:54 -07002906 return row.getVisibility() == View.INVISIBLE;
Selim Cinekb5605e52015-02-20 18:21:41 +01002907 }
2908 }
2909 return false;
2910 }
2911
2912 /**
Selim Cinek572bbd42014-04-25 16:43:27 +02002913 * Updates the scroll position when a child was removed
2914 *
2915 * @param removedChild the removed child
2916 */
Selim Cinek61633a82016-01-25 15:54:10 -08002917 private void updateScrollStateForRemovedChild(ExpandableView removedChild) {
Selim Cinek572bbd42014-04-25 16:43:27 +02002918 int startingPosition = getPositionInLinearLayout(removedChild);
Selim Cineka7ed2c12017-01-23 20:47:24 -08002919 float increasedPaddingAmount = removedChild.getIncreasedPaddingAmount();
2920 int padding;
2921 if (increasedPaddingAmount >= 0) {
2922 padding = (int) NotificationUtils.interpolate(
2923 mPaddingBetweenElements,
2924 mIncreasedPaddingBetweenElements,
2925 increasedPaddingAmount);
2926 } else {
2927 padding = (int) NotificationUtils.interpolate(
2928 0,
2929 mPaddingBetweenElements,
2930 1.0f + increasedPaddingAmount);
2931 }
Selim Cinek61633a82016-01-25 15:54:10 -08002932 int childHeight = getIntrinsicHeight(removedChild) + padding;
Selim Cinek572bbd42014-04-25 16:43:27 +02002933 int endPosition = startingPosition + childHeight;
2934 if (endPosition <= mOwnScrollY) {
2935 // This child is fully scrolled of the top, so we have to deduct its height from the
2936 // scrollPosition
Selim Cinekef406062016-09-29 17:33:13 -07002937 setOwnScrollY(mOwnScrollY - childHeight);
Selim Cinek572bbd42014-04-25 16:43:27 +02002938 } else if (startingPosition < mOwnScrollY) {
2939 // This child is currently being scrolled into, set the scroll position to the start of
2940 // this child
Selim Cinekef406062016-09-29 17:33:13 -07002941 setOwnScrollY(startingPosition);
Selim Cinek572bbd42014-04-25 16:43:27 +02002942 }
2943 }
2944
Selim Cinekd7c4e002014-07-04 18:36:42 +02002945 private int getIntrinsicHeight(View view) {
2946 if (view instanceof ExpandableView) {
2947 ExpandableView expandableView = (ExpandableView) view;
2948 return expandableView.getIntrinsicHeight();
2949 }
2950 return view.getHeight();
2951 }
2952
Selim Cinek1f624952017-06-08 19:11:50 -07002953 public int getPositionInLinearLayout(View requestedView) {
Adrian Roos4a579672016-05-24 16:54:37 -07002954 ExpandableNotificationRow childInGroup = null;
2955 ExpandableNotificationRow requestedRow = null;
2956 if (isChildInGroup(requestedView)) {
2957 // We're asking for a child in a group. Calculate the position of the parent first,
2958 // then within the parent.
2959 childInGroup = (ExpandableNotificationRow) requestedView;
2960 requestedView = requestedRow = childInGroup.getNotificationParent();
2961 }
Selim Cinek572bbd42014-04-25 16:43:27 +02002962 int position = 0;
Selim Cineka7ed2c12017-01-23 20:47:24 -08002963 float previousPaddingRequest = mPaddingBetweenElements;
2964 float previousPaddingAmount = 0.0f;
Selim Cinek572bbd42014-04-25 16:43:27 +02002965 for (int i = 0; i < getChildCount(); i++) {
Selim Cinek61633a82016-01-25 15:54:10 -08002966 ExpandableView child = (ExpandableView) getChildAt(i);
2967 boolean notGone = child.getVisibility() != View.GONE;
Selim Cinek281c2022016-10-13 19:14:43 -07002968 if (notGone && !child.hasNoContentHeight()) {
Selim Cinek42357e02016-02-24 18:48:01 -08002969 float increasedPaddingAmount = child.getIncreasedPaddingAmount();
Selim Cineka7ed2c12017-01-23 20:47:24 -08002970 float padding;
2971 if (increasedPaddingAmount >= 0.0f) {
2972 padding = (int) NotificationUtils.interpolate(
2973 previousPaddingRequest,
2974 mIncreasedPaddingBetweenElements,
2975 increasedPaddingAmount);
2976 previousPaddingRequest = (int) NotificationUtils.interpolate(
Selim Cinek42357e02016-02-24 18:48:01 -08002977 mPaddingBetweenElements,
2978 mIncreasedPaddingBetweenElements,
Selim Cineka7ed2c12017-01-23 20:47:24 -08002979 increasedPaddingAmount);
2980 } else {
2981 int ownPadding = (int) NotificationUtils.interpolate(
2982 0,
2983 mPaddingBetweenElements,
2984 1.0f + increasedPaddingAmount);
2985 if (previousPaddingAmount > 0.0f) {
2986 padding = (int) NotificationUtils.interpolate(
2987 ownPadding,
2988 mIncreasedPaddingBetweenElements,
2989 previousPaddingAmount);
2990 } else {
2991 padding = ownPadding;
2992 }
2993 previousPaddingRequest = ownPadding;
Selim Cinek61633a82016-01-25 15:54:10 -08002994 }
Selim Cineka7ed2c12017-01-23 20:47:24 -08002995 if (position != 0) {
2996 position += padding;
2997 }
2998 previousPaddingAmount = increasedPaddingAmount;
Selim Cinek61633a82016-01-25 15:54:10 -08002999 }
Adrian Roos4a579672016-05-24 16:54:37 -07003000 if (child == requestedView) {
3001 if (requestedRow != null) {
3002 position += requestedRow.getPositionOfChild(childInGroup);
3003 }
Selim Cinek572bbd42014-04-25 16:43:27 +02003004 return position;
3005 }
Selim Cinek61633a82016-01-25 15:54:10 -08003006 if (notGone) {
Selim Cinekabdc5a02014-09-02 13:46:00 +02003007 position += getIntrinsicHeight(child);
Selim Cinek572bbd42014-04-25 16:43:27 +02003008 }
3009 }
3010 return 0;
Selim Cinek1685e632014-04-08 02:27:49 +02003011 }
3012
3013 @Override
Adam Powell6690d012015-06-17 16:41:56 -07003014 public void onViewAdded(View child) {
Selim Cinek1685e632014-04-08 02:27:49 +02003015 super.onViewAdded(child);
Selim Cinekb5605e52015-02-20 18:21:41 +01003016 onViewAddedInternal(child);
3017 }
3018
Selim Cinek614576e2016-01-20 10:54:09 -08003019 private void updateFirstAndLastBackgroundViews() {
3020 ActivatableNotificationView firstChild = getFirstChildWithBackground();
3021 ActivatableNotificationView lastChild = getLastChildWithBackground();
3022 if (mAnimationsEnabled && mIsExpanded) {
Selim Cinek29aab962018-02-27 17:05:45 -08003023 mAnimateNextBackgroundTop = firstChild != mFirstVisibleBackgroundChild;
3024 mAnimateNextBackgroundBottom = lastChild != mLastVisibleBackgroundChild;
Selim Cinek614576e2016-01-20 10:54:09 -08003025 } else {
3026 mAnimateNextBackgroundTop = false;
3027 mAnimateNextBackgroundBottom = false;
3028 }
3029 mFirstVisibleBackgroundChild = firstChild;
3030 mLastVisibleBackgroundChild = lastChild;
Selim Cinekdb167372016-11-17 15:41:17 -08003031 mAmbientState.setLastVisibleBackgroundChild(lastChild);
Selim Cinek29aab962018-02-27 17:05:45 -08003032 mRoundnessManager.setFirstAndLastBackgroundChild(mFirstVisibleBackgroundChild,
3033 mLastVisibleBackgroundChild);
Selim Cinek515b2032017-11-15 10:20:19 -08003034 invalidate();
Selim Cinek614576e2016-01-20 10:54:09 -08003035 }
3036
Selim Cinekb5605e52015-02-20 18:21:41 +01003037 private void onViewAddedInternal(View child) {
Selim Cinekd06c41c2015-07-06 14:51:36 -07003038 updateHideSensitiveForChild(child);
Jorim Jaggibe565df2014-04-28 17:51:23 +02003039 ((ExpandableView) child).setOnHeightChangedListener(this);
Jorim Jaggif6411742014-08-05 17:10:43 +00003040 generateAddAnimation(child, false /* fromMoreCard */);
Selim Cinek51ae05d2014-09-09 15:51:38 +02003041 updateAnimationState(child);
Selim Cinek98713a42015-09-21 15:47:20 +02003042 updateChronometerForChild(child);
Selim Cinek572bbd42014-04-25 16:43:27 +02003043 }
3044
Selim Cinekd06c41c2015-07-06 14:51:36 -07003045 private void updateHideSensitiveForChild(View child) {
Selim Cinekcfcd23e2016-05-05 12:31:42 -04003046 if (child instanceof ExpandableView) {
Selim Cinekd06c41c2015-07-06 14:51:36 -07003047 ExpandableView expandableView = (ExpandableView) child;
Selim Cinekcfcd23e2016-05-05 12:31:42 -04003048 expandableView.setHideSensitiveForIntrinsicHeight(mAmbientState.isHideSensitive());
Selim Cinekd06c41c2015-07-06 14:51:36 -07003049 }
3050 }
3051
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09003052 @Override
Selim Cinekd1395642016-04-28 12:22:42 -07003053 public void notifyGroupChildRemoved(View row, ViewGroup childrenContainer) {
3054 onViewRemovedInternal(row, childrenContainer);
Selim Cinekb5605e52015-02-20 18:21:41 +01003055 }
3056
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09003057 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01003058 public void notifyGroupChildAdded(View row) {
3059 onViewAddedInternal(row);
3060 }
3061
Jorim Jaggi75c95042014-05-16 19:09:59 +02003062 public void setAnimationsEnabled(boolean animationsEnabled) {
3063 mAnimationsEnabled = animationsEnabled;
Selim Cinekcab4a602014-09-03 14:47:57 +02003064 updateNotificationAnimationStates();
Rohan Shah8ee53652018-04-05 11:13:50 -07003065 if (!animationsEnabled) {
3066 mSwipedOutViews.clear();
3067 mChildrenToRemoveAnimated.clear();
3068 clearTemporaryViewsInGroup(this);
3069 }
Selim Cinekcab4a602014-09-03 14:47:57 +02003070 }
3071
3072 private void updateNotificationAnimationStates() {
Selim Cinekbe2c4432017-05-30 12:11:09 -07003073 boolean running = mAnimationsEnabled || hasPulsingNotifications();
Selim Cinek09bd29d2017-02-03 15:30:28 -08003074 mShelf.setAnimationsEnabled(running);
Selim Cinekcab4a602014-09-03 14:47:57 +02003075 int childCount = getChildCount();
3076 for (int i = 0; i < childCount; i++) {
3077 View child = getChildAt(i);
Selim Cinek8d490d42015-04-10 00:05:50 -07003078 running &= mIsExpanded || isPinnedHeadsUp(child);
Selim Cinekcab4a602014-09-03 14:47:57 +02003079 updateAnimationState(running, child);
3080 }
3081 }
3082
Selim Cinek51ae05d2014-09-09 15:51:38 +02003083 private void updateAnimationState(View child) {
Selim Cinekbe2c4432017-05-30 12:11:09 -07003084 updateAnimationState((mAnimationsEnabled || hasPulsingNotifications())
Selim Cinekcd5b22f2016-03-08 16:15:41 -08003085 && (mIsExpanded || isPinnedHeadsUp(child)), child);
Selim Cinek51ae05d2014-09-09 15:51:38 +02003086 }
3087
Selim Cinek2627d722018-01-19 12:16:49 -08003088 @Override
3089 public void setExpandingNotification(ExpandableNotificationRow row) {
3090 mAmbientState.setExpandingNotification(row);
3091 requestChildrenUpdate();
3092 }
3093
3094 @Override
Selim Cinek8875de12018-03-22 10:14:32 -07003095 public void bindRow(ExpandableNotificationRow row) {
Selim Cinekf0c79e12018-05-14 17:17:31 -07003096 row.setHeadsUpAnimatingAwayListener(animatingAway -> {
3097 mRoundnessManager.onHeadsupAnimatingAwayChanged(row, animatingAway);
3098 mHeadsUpAppearanceController.updateHeader(row.getEntry());
3099 });
Selim Cinek8875de12018-03-22 10:14:32 -07003100 }
3101
3102 @Override
Selim Cinek2627d722018-01-19 12:16:49 -08003103 public void applyExpandAnimationParams(ExpandAnimationParameters params) {
3104 mAmbientState.setExpandAnimationTopChange(params == null ? 0 : params.getTopChange());
3105 requestChildrenUpdate();
3106 }
Selim Cinek51ae05d2014-09-09 15:51:38 +02003107
Selim Cinekcab4a602014-09-03 14:47:57 +02003108 private void updateAnimationState(boolean running, View child) {
3109 if (child instanceof ExpandableNotificationRow) {
3110 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
3111 row.setIconAnimationRunning(running);
3112 }
Jorim Jaggi75c95042014-05-16 19:09:59 +02003113 }
3114
3115 public boolean isAddOrRemoveAnimationPending() {
3116 return mNeedsAnimation
3117 && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty());
3118 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09003119
3120 @Override
Jorim Jaggif6411742014-08-05 17:10:43 +00003121 public void generateAddAnimation(View child, boolean fromMoreCard) {
Selim Cinek159ffdb2014-06-04 22:24:18 +02003122 if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) {
Selim Cinek572bbd42014-04-25 16:43:27 +02003123 // Generate Animations
3124 mChildrenToAddAnimated.add(child);
Jorim Jaggif6411742014-08-05 17:10:43 +00003125 if (fromMoreCard) {
3126 mFromMoreCardAdditions.add(child);
3127 }
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003128 mNeedsAnimation = true;
Selim Cinek572bbd42014-04-25 16:43:27 +02003129 }
Selim Cinekf306d9b2017-02-21 11:45:13 -08003130 if (isHeadsUp(child) && mAnimationsEnabled && !mChangePositionInProgress) {
Selim Cineka59ecc32015-04-07 10:51:49 -07003131 mAddedHeadsUpChildren.add(child);
3132 mChildrenToAddAnimated.remove(child);
3133 }
Selim Cinek572bbd42014-04-25 16:43:27 +02003134 }
3135
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09003136 @Override
Selim Cinek572bbd42014-04-25 16:43:27 +02003137 public void changeViewPosition(View child, int newIndex) {
Dan Sandlereceda3d2014-07-21 15:35:01 -04003138 int currentIndex = indexOfChild(child);
Rohan Shah8ee53652018-04-05 11:13:50 -07003139
3140 if (currentIndex == -1) {
3141 boolean isTransient = false;
3142 if (child instanceof ExpandableNotificationRow
3143 && ((ExpandableNotificationRow)child).getTransientContainer() != null) {
3144 isTransient = true;
3145 }
3146 Log.e(TAG, "Attempting to re-position "
3147 + (isTransient ? "transient" : "")
3148 + " view {"
3149 + child
3150 + "}");
3151 return;
3152 }
3153
Dan Sandlereceda3d2014-07-21 15:35:01 -04003154 if (child != null && child.getParent() == this && currentIndex != newIndex) {
Selim Cinek159ffdb2014-06-04 22:24:18 +02003155 mChangePositionInProgress = true;
Adrian Roos14503e22016-03-09 14:01:24 -08003156 ((ExpandableView)child).setChangingPosition(true);
Selim Cinekc27437b2014-05-14 10:23:33 +02003157 removeView(child);
3158 addView(child, newIndex);
Adrian Roos14503e22016-03-09 14:01:24 -08003159 ((ExpandableView)child).setChangingPosition(false);
Selim Cinek159ffdb2014-06-04 22:24:18 +02003160 mChangePositionInProgress = false;
Dan Sandlereceda3d2014-07-21 15:35:01 -04003161 if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) {
Selim Cinek159ffdb2014-06-04 22:24:18 +02003162 mChildrenChangingPositions.add(child);
3163 mNeedsAnimation = true;
3164 }
Selim Cinek572bbd42014-04-25 16:43:27 +02003165 }
3166 }
3167
Selim Cinekf4c19962014-05-01 21:55:31 +02003168 private void startAnimationToState() {
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003169 if (mNeedsAnimation) {
Selim Cinek572bbd42014-04-25 16:43:27 +02003170 generateChildHierarchyEvents();
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003171 mNeedsAnimation = false;
Selim Cinek572bbd42014-04-25 16:43:27 +02003172 }
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003173 if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) {
Selim Cinekea66ca02016-05-24 13:33:47 -07003174 setAnimationRunning(true);
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02003175 mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState,
3176 mGoToFullShadeDelay);
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003177 mAnimationEvents.clear();
Selim Cinek6811d722016-01-19 17:53:12 -08003178 updateBackground();
Selim Cinek33223572016-02-19 19:32:22 -08003179 updateViewShadows();
Selim Cinekb0ee18f2017-12-21 16:15:53 -08003180 updateClippingToTopRoundedCorner();
Selim Cinekf4c19962014-05-01 21:55:31 +02003181 } else {
3182 applyCurrentState();
3183 }
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02003184 mGoToFullShadeDelay = 0;
Selim Cinek572bbd42014-04-25 16:43:27 +02003185 }
3186
3187 private void generateChildHierarchyEvents() {
Selim Cineka59ecc32015-04-07 10:51:49 -07003188 generateHeadsUpAnimationEvents();
Selim Cinek572bbd42014-04-25 16:43:27 +02003189 generateChildRemovalEvents();
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003190 generateChildAdditionEvents();
3191 generatePositionChangeEvents();
Selim Cinekeb973562014-05-02 17:07:49 +02003192 generateSnapBackEvents();
3193 generateDragEvents();
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003194 generateTopPaddingEvent();
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003195 generateActivateEvent();
3196 generateDimmedEvent();
Jorim Jaggiae441282014-08-01 02:45:18 +02003197 generateHideSensitiveEvent();
John Spurlockbf370992014-06-17 13:58:31 -04003198 generateDarkEvent();
Jorim Jaggi60d07c52014-07-31 15:38:21 +02003199 generateGoToFullShadeEvent();
Selim Cineka5e211b2014-08-11 17:35:48 +02003200 generateViewResizeEvent();
Selim Cinekb5605e52015-02-20 18:21:41 +01003201 generateGroupExpansionEvent();
Selim Cinekd9acca52014-09-01 22:33:25 +02003202 generateAnimateEverythingEvent();
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07003203 generatePulsingAnimationEvent();
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003204 mNeedsAnimation = false;
Selim Cinek572bbd42014-04-25 16:43:27 +02003205 }
3206
Selim Cinekb8f09cf2015-03-16 17:09:28 -07003207 private void generateHeadsUpAnimationEvents() {
3208 for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) {
Selim Cineka59ecc32015-04-07 10:51:49 -07003209 ExpandableNotificationRow row = eventPair.first;
3210 boolean isHeadsUp = eventPair.second;
3211 int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER;
3212 boolean onBottom = false;
Selim Cinek131c1e22015-05-11 19:04:49 -07003213 boolean pinnedAndClosed = row.isPinned() && !mIsExpanded;
Selim Cinekaac93252015-04-14 20:04:12 -07003214 if (!mIsExpanded && !isHeadsUp) {
Jorim Jaggi5eb67c22015-08-19 19:50:49 -07003215 type = row.wasJustClicked()
3216 ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK
3217 : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR;
Selim Cinek76e813c2016-07-14 11:16:58 -07003218 if (row.isChildInGroup()) {
3219 // We can otherwise get stuck in there if it was just isolated
Selim Cinekcafa87f2016-10-26 17:00:17 -07003220 row.setHeadsUpAnimatingAway(false);
Selim Cinekf93bf3e2018-05-08 14:43:21 -07003221 continue;
Selim Cinek76e813c2016-07-14 11:16:58 -07003222 }
Selim Cinekeaee9c02015-06-25 11:04:20 -04003223 } else {
Selim Cinekbbcebde2016-11-09 18:28:20 -08003224 ExpandableViewState viewState = mCurrentStackScrollState.getViewStateForView(row);
Selim Cinekeaee9c02015-06-25 11:04:20 -04003225 if (viewState == null) {
3226 // A view state was never generated for this view, so we don't need to animate
3227 // this. This may happen with notification children.
3228 continue;
Selim Cineka59ecc32015-04-07 10:51:49 -07003229 }
Selim Cinekeaee9c02015-06-25 11:04:20 -04003230 if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) {
3231 if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) {
3232 // Our custom add animation
3233 type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR;
3234 } else {
3235 // Normal add animation
3236 type = AnimationEvent.ANIMATION_TYPE_ADD;
3237 }
3238 onBottom = !pinnedAndClosed;
3239 }
Selim Cineka59ecc32015-04-07 10:51:49 -07003240 }
3241 AnimationEvent event = new AnimationEvent(row, type);
3242 event.headsUpFromBottom = onBottom;
3243 mAnimationEvents.add(event);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07003244 }
3245 mHeadsUpChangeAnimations.clear();
Selim Cineka59ecc32015-04-07 10:51:49 -07003246 mAddedHeadsUpChildren.clear();
3247 }
3248
Selim Cinekbbcebde2016-11-09 18:28:20 -08003249 private boolean shouldHunAppearFromBottom(ExpandableViewState viewState) {
Selim Cineka59ecc32015-04-07 10:51:49 -07003250 if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) {
3251 return false;
3252 }
3253 return true;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07003254 }
3255
Selim Cinekb5605e52015-02-20 18:21:41 +01003256 private void generateGroupExpansionEvent() {
3257 // Generate a group expansion/collapsing event if there is such a group at all
3258 if (mExpandedGroupView != null) {
3259 mAnimationEvents.add(new AnimationEvent(mExpandedGroupView,
3260 AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED));
3261 mExpandedGroupView = null;
3262 }
3263 }
3264
Selim Cineka5e211b2014-08-11 17:35:48 +02003265 private void generateViewResizeEvent() {
3266 if (mNeedViewResizeAnimation) {
3267 mAnimationEvents.add(
3268 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE));
3269 }
3270 mNeedViewResizeAnimation = false;
3271 }
3272
Selim Cinekeb973562014-05-02 17:07:49 +02003273 private void generateSnapBackEvents() {
3274 for (View child : mSnappedBackChildren) {
3275 mAnimationEvents.add(new AnimationEvent(child,
3276 AnimationEvent.ANIMATION_TYPE_SNAP_BACK));
3277 }
3278 mSnappedBackChildren.clear();
3279 }
3280
3281 private void generateDragEvents() {
3282 for (View child : mDragAnimPendingChildren) {
3283 mAnimationEvents.add(new AnimationEvent(child,
3284 AnimationEvent.ANIMATION_TYPE_START_DRAG));
3285 }
3286 mDragAnimPendingChildren.clear();
3287 }
3288
Selim Cinek572bbd42014-04-25 16:43:27 +02003289 private void generateChildRemovalEvents() {
Selim Cinekeb973562014-05-02 17:07:49 +02003290 for (View child : mChildrenToRemoveAnimated) {
Selim Cinek572bbd42014-04-25 16:43:27 +02003291 boolean childWasSwipedOut = mSwipedOutViews.contains(child);
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003292
3293 // we need to know the view after this one
Selim Cinekef8c2252017-02-10 14:52:18 -08003294 float removedTranslation = child.getTranslationY();
3295 boolean ignoreChildren = true;
3296 if (child instanceof ExpandableNotificationRow) {
3297 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
3298 if (row.isRemoved() && row.wasChildInGroupWhenRemoved()) {
3299 removedTranslation = row.getTranslationWhenRemoved();
3300 ignoreChildren = false;
3301 }
Selim Cinek51052042017-07-04 12:07:55 +02003302 childWasSwipedOut |= Math.abs(row.getTranslation()) == row.getWidth();
Selim Cinekef8c2252017-02-10 14:52:18 -08003303 }
Selim Cinek51052042017-07-04 12:07:55 +02003304 if (!childWasSwipedOut) {
3305 Rect clipBounds = child.getClipBounds();
Selim Cineke5832ee2017-11-06 14:46:48 -08003306 childWasSwipedOut = clipBounds != null && clipBounds.height() == 0;
Rohan Shaha7594962018-05-22 10:59:30 -07003307
3308 if (childWasSwipedOut && child instanceof ExpandableView) {
3309 // Clean up any potential transient views if the child has already been swiped
3310 // out, as we won't be animating it further (due to its height already being
3311 // clipped to 0.
3312 ViewGroup transientContainer = ((ExpandableView) child).getTransientContainer();
3313 if (transientContainer != null) {
3314 transientContainer.removeTransientView(child);
3315 }
3316 }
Selim Cinek51052042017-07-04 12:07:55 +02003317 }
3318 int animationType = childWasSwipedOut
3319 ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT
3320 : AnimationEvent.ANIMATION_TYPE_REMOVE;
3321 AnimationEvent event = new AnimationEvent(child, animationType);
Selim Cinekef8c2252017-02-10 14:52:18 -08003322 event.viewAfterChangingView = getFirstChildBelowTranlsationY(removedTranslation,
3323 ignoreChildren);
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003324 mAnimationEvents.add(event);
Selim Cinekd1395642016-04-28 12:22:42 -07003325 mSwipedOutViews.remove(child);
Selim Cinek572bbd42014-04-25 16:43:27 +02003326 }
Selim Cinek572bbd42014-04-25 16:43:27 +02003327 mChildrenToRemoveAnimated.clear();
3328 }
3329
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003330 private void generatePositionChangeEvents() {
3331 for (View child : mChildrenChangingPositions) {
3332 mAnimationEvents.add(new AnimationEvent(child,
3333 AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION));
3334 }
3335 mChildrenChangingPositions.clear();
Selim Cinekb5605e52015-02-20 18:21:41 +01003336 if (mGenerateChildOrderChangedEvent) {
3337 mAnimationEvents.add(new AnimationEvent(null,
3338 AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION));
3339 mGenerateChildOrderChangedEvent = false;
3340 }
Selim Cinek8efa6dd2014-05-19 16:27:37 +02003341 }
3342
Selim Cinek572bbd42014-04-25 16:43:27 +02003343 private void generateChildAdditionEvents() {
Selim Cinekeb973562014-05-02 17:07:49 +02003344 for (View child : mChildrenToAddAnimated) {
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02003345 if (mFromMoreCardAdditions.contains(child)) {
3346 mAnimationEvents.add(new AnimationEvent(child,
3347 AnimationEvent.ANIMATION_TYPE_ADD,
3348 StackStateAnimator.ANIMATION_DURATION_STANDARD));
3349 } else {
3350 mAnimationEvents.add(new AnimationEvent(child,
3351 AnimationEvent.ANIMATION_TYPE_ADD));
3352 }
Selim Cinek572bbd42014-04-25 16:43:27 +02003353 }
3354 mChildrenToAddAnimated.clear();
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02003355 mFromMoreCardAdditions.clear();
Christoph Studer068f5922014-04-08 17:43:07 -04003356 }
3357
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003358 private void generateTopPaddingEvent() {
Jorim Jaggi98fb09c2014-05-01 22:40:56 +02003359 if (mTopPaddingNeedsAnimation) {
Lucas Dupinc445dcc2018-05-07 16:00:11 -07003360 AnimationEvent event;
3361 if (mAmbientState.isDark()) {
3362 event = new AnimationEvent(null /* view */,
3363 AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED,
3364 KeyguardSliceView.DEFAULT_ANIM_DURATION);
3365 } else {
3366 event = new AnimationEvent(null /* view */,
3367 AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED);
3368 }
3369 mAnimationEvents.add(event);
Jorim Jaggi98fb09c2014-05-01 22:40:56 +02003370 }
Jorim Jaggi0dd68812014-05-01 19:17:37 +02003371 mTopPaddingNeedsAnimation = false;
3372 }
3373
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003374 private void generateActivateEvent() {
3375 if (mActivateNeedsAnimation) {
3376 mAnimationEvents.add(
3377 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD));
3378 }
3379 mActivateNeedsAnimation = false;
3380 }
3381
Selim Cinekd9acca52014-09-01 22:33:25 +02003382 private void generateAnimateEverythingEvent() {
3383 if (mEverythingNeedsAnimation) {
3384 mAnimationEvents.add(
3385 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING));
3386 }
3387 mEverythingNeedsAnimation = false;
3388 }
3389
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003390 private void generateDimmedEvent() {
3391 if (mDimmedNeedsAnimation) {
3392 mAnimationEvents.add(
3393 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED));
3394 }
3395 mDimmedNeedsAnimation = false;
3396 }
3397
Jorim Jaggiae441282014-08-01 02:45:18 +02003398 private void generateHideSensitiveEvent() {
3399 if (mHideSensitiveNeedsAnimation) {
3400 mAnimationEvents.add(
3401 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE));
3402 }
3403 mHideSensitiveNeedsAnimation = false;
3404 }
3405
John Spurlockbf370992014-06-17 13:58:31 -04003406 private void generateDarkEvent() {
3407 if (mDarkNeedsAnimation) {
Adrian Roos28f90c72017-05-08 17:24:26 -07003408 AnimationEvent ev = new AnimationEvent(null,
3409 AnimationEvent.ANIMATION_TYPE_DARK,
3410 new AnimationFilter()
3411 .animateDark()
3412 .animateY(mShelf));
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01003413 ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex;
3414 mAnimationEvents.add(ev);
John Spurlockbf370992014-06-17 13:58:31 -04003415 }
3416 mDarkNeedsAnimation = false;
3417 }
3418
Jorim Jaggi60d07c52014-07-31 15:38:21 +02003419 private void generateGoToFullShadeEvent() {
3420 if (mGoToFullShadeNeedsAnimation) {
3421 mAnimationEvents.add(
3422 new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE));
3423 }
3424 mGoToFullShadeNeedsAnimation = false;
3425 }
3426
Selim Cinek67b22602014-03-10 15:40:16 +01003427 private boolean onInterceptTouchEventScroll(MotionEvent ev) {
Selim Cinek1408eb52014-06-02 14:45:38 +02003428 if (!isScrollingEnabled()) {
3429 return false;
3430 }
Selim Cinek67b22602014-03-10 15:40:16 +01003431 /*
3432 * This method JUST determines whether we want to intercept the motion.
3433 * If we return true, onMotionEvent will be called and we do the actual
3434 * scrolling there.
3435 */
3436
3437 /*
3438 * Shortcut the most recurring case: the user is in the dragging
Chris Wren5d53df42015-06-26 11:26:03 -04003439 * state and is moving their finger. We want to intercept this
Selim Cinek67b22602014-03-10 15:40:16 +01003440 * motion.
3441 */
3442 final int action = ev.getAction();
3443 if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) {
3444 return true;
3445 }
3446
Selim Cinek67b22602014-03-10 15:40:16 +01003447 switch (action & MotionEvent.ACTION_MASK) {
3448 case MotionEvent.ACTION_MOVE: {
3449 /*
3450 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
Chris Wren5d53df42015-06-26 11:26:03 -04003451 * whether the user has moved far enough from the original down touch.
Selim Cinek67b22602014-03-10 15:40:16 +01003452 */
3453
3454 /*
3455 * Locally do absolute value. mLastMotionY is set to the y value
3456 * of the down event.
3457 */
3458 final int activePointerId = mActivePointerId;
3459 if (activePointerId == INVALID_POINTER) {
3460 // If we don't have a valid id, the touch down wasn't on content.
3461 break;
3462 }
3463
3464 final int pointerIndex = ev.findPointerIndex(activePointerId);
3465 if (pointerIndex == -1) {
3466 Log.e(TAG, "Invalid pointerId=" + activePointerId
3467 + " in onInterceptTouchEvent");
3468 break;
3469 }
3470
3471 final int y = (int) ev.getY(pointerIndex);
Selim Cinek1408eb52014-06-02 14:45:38 +02003472 final int x = (int) ev.getX(pointerIndex);
Selim Cinek67b22602014-03-10 15:40:16 +01003473 final int yDiff = Math.abs(y - mLastMotionY);
Selim Cinek1408eb52014-06-02 14:45:38 +02003474 final int xDiff = Math.abs(x - mDownX);
3475 if (yDiff > mTouchSlop && yDiff > xDiff) {
Selim Cinek67b22602014-03-10 15:40:16 +01003476 setIsBeingDragged(true);
3477 mLastMotionY = y;
Selim Cinek1408eb52014-06-02 14:45:38 +02003478 mDownX = x;
Selim Cinek67b22602014-03-10 15:40:16 +01003479 initVelocityTrackerIfNotExists();
3480 mVelocityTracker.addMovement(ev);
Selim Cinek67b22602014-03-10 15:40:16 +01003481 }
3482 break;
3483 }
3484
3485 case MotionEvent.ACTION_DOWN: {
3486 final int y = (int) ev.getY();
Jayasri bhattacharyya5e55c892015-09-10 16:00:10 +05303487 mScrolledToTopOnFirstDown = isScrolledToTop();
Selim Cinek34ed7c02017-09-08 15:03:12 -07003488 if (getChildAtPosition(ev.getX(), y, false /* requireMinHeight */) == null) {
Selim Cinek67b22602014-03-10 15:40:16 +01003489 setIsBeingDragged(false);
3490 recycleVelocityTracker();
3491 break;
3492 }
3493
3494 /*
3495 * Remember location of down touch.
3496 * ACTION_DOWN always refers to pointer index 0.
3497 */
3498 mLastMotionY = y;
Selim Cinek1408eb52014-06-02 14:45:38 +02003499 mDownX = (int) ev.getX();
Selim Cinek67b22602014-03-10 15:40:16 +01003500 mActivePointerId = ev.getPointerId(0);
3501
3502 initOrResetVelocityTracker();
3503 mVelocityTracker.addMovement(ev);
3504 /*
3505 * If being flinged and user touches the screen, initiate drag;
3506 * otherwise don't. mScroller.isFinished should be false when
3507 * being flinged.
3508 */
3509 boolean isBeingDragged = !mScroller.isFinished();
3510 setIsBeingDragged(isBeingDragged);
3511 break;
3512 }
3513
3514 case MotionEvent.ACTION_CANCEL:
3515 case MotionEvent.ACTION_UP:
3516 /* Release the drag */
3517 setIsBeingDragged(false);
3518 mActivePointerId = INVALID_POINTER;
3519 recycleVelocityTracker();
3520 if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) {
Selim Cinek9212de82017-02-06 16:04:28 -08003521 animateScroll();
Selim Cinek67b22602014-03-10 15:40:16 +01003522 }
3523 break;
3524 case MotionEvent.ACTION_POINTER_UP:
3525 onSecondaryPointerUp(ev);
3526 break;
3527 }
3528
3529 /*
3530 * The only time we want to intercept motion events is if we are in the
3531 * drag mode.
3532 */
3533 return mIsBeingDragged;
3534 }
3535
Muyuan Li333a4fc2016-04-16 17:13:46 -07003536 protected StackScrollAlgorithm createStackScrollAlgorithm(Context context) {
3537 return new StackScrollAlgorithm(context);
3538 }
3539
Jorim Jaggife6bfa62014-05-07 23:23:18 +02003540 /**
3541 * @return Whether the specified motion event is actually happening over the content.
3542 */
3543 private boolean isInContentBounds(MotionEvent event) {
Selim Cinekab1dc952014-10-30 20:20:29 +01003544 return isInContentBounds(event.getY());
3545 }
3546
3547 /**
3548 * @return Whether a y coordinate is inside the content.
3549 */
3550 public boolean isInContentBounds(float y) {
3551 return y < getHeight() - getEmptyBottomMargin();
Jorim Jaggife6bfa62014-05-07 23:23:18 +02003552 }
3553
Selim Cinek67b22602014-03-10 15:40:16 +01003554 private void setIsBeingDragged(boolean isDragged) {
3555 mIsBeingDragged = isDragged;
3556 if (isDragged) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +01003557 requestDisallowInterceptTouchEvent(true);
Geoffrey Pitsch409db272017-08-28 14:51:52 +00003558 cancelLongPress();
Selim Cinek67b22602014-03-10 15:40:16 +01003559 }
3560 }
3561
3562 @Override
3563 public void onWindowFocusChanged(boolean hasWindowFocus) {
3564 super.onWindowFocusChanged(hasWindowFocus);
3565 if (!hasWindowFocus) {
Geoffrey Pitsch409db272017-08-28 14:51:52 +00003566 cancelLongPress();
Selim Cinek67b22602014-03-10 15:40:16 +01003567 }
3568 }
Selim Cinekfab078b2014-03-27 22:45:58 +01003569
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07003570 @Override
Adrian Roos181385c2016-05-05 17:45:44 -04003571 public void clearChildFocus(View child) {
3572 super.clearChildFocus(child);
3573 if (mForcedScroll == child) {
3574 mForcedScroll = null;
3575 }
3576 }
3577
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07003578 public void requestDisallowLongPress() {
Geoffrey Pitsch409db272017-08-28 14:51:52 +00003579 cancelLongPress();
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07003580 }
3581
Adrian Roosfa139752016-04-27 09:59:08 -07003582 public void requestDisallowDismiss() {
3583 mDisallowDismissInThisMotion = true;
3584 }
3585
Geoffrey Pitsch409db272017-08-28 14:51:52 +00003586 public void cancelLongPress() {
3587 mSwipeHelper.cancelLongPress();
Selim Cinek1408eb52014-06-02 14:45:38 +02003588 }
3589
Selim Cinekfab078b2014-03-27 22:45:58 +01003590 @Override
3591 public boolean isScrolledToTop() {
3592 return mOwnScrollY == 0;
3593 }
3594
3595 @Override
Selim Cinekb6d85eb2014-03-28 20:21:01 +01003596 public boolean isScrolledToBottom() {
3597 return mOwnScrollY >= getScrollRange();
3598 }
3599
3600 @Override
Selim Cinekfab078b2014-03-27 22:45:58 +01003601 public View getHostView() {
3602 return this;
3603 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +02003604
Selim Cinekb6d85eb2014-03-28 20:21:01 +01003605 public int getEmptyBottomMargin() {
Selim Cinekdb167372016-11-17 15:41:17 -08003606 return Math.max(mMaxLayoutHeight - mContentHeight, 0);
Selim Cinekb6d85eb2014-03-28 20:21:01 +01003607 }
3608
Mady Mellorc2dbe492017-03-30 13:22:03 -07003609 public void checkSnoozeLeavebehind() {
3610 if (mCheckForLeavebehind) {
Eliot Courtney47098cb2017-10-18 17:30:30 +09003611 mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */,
3612 false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */,
3613 false /* resetMenu */);
Mady Mellorc2dbe492017-03-30 13:22:03 -07003614 mCheckForLeavebehind = false;
3615 }
3616 }
3617
3618 public void resetCheckSnoozeLeavebehind() {
3619 mCheckForLeavebehind = true;
3620 }
3621
Selim Cinek1685e632014-04-08 02:27:49 +02003622 public void onExpansionStarted() {
Selim Cinekc27437b2014-05-14 10:23:33 +02003623 mIsExpansionChanging = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -08003624 mAmbientState.setExpansionChanging(true);
Mady Mellorc2dbe492017-03-30 13:22:03 -07003625 checkSnoozeLeavebehind();
Selim Cinek1685e632014-04-08 02:27:49 +02003626 }
3627
3628 public void onExpansionStopped() {
Selim Cinekc27437b2014-05-14 10:23:33 +02003629 mIsExpansionChanging = false;
Mady Mellorc2dbe492017-03-30 13:22:03 -07003630 resetCheckSnoozeLeavebehind();
Selim Cinekd5ab6452016-12-08 16:34:00 -08003631 mAmbientState.setExpansionChanging(false);
Selim Cinek4fe3e472014-07-03 16:32:54 +02003632 if (!mIsExpanded) {
Selim Cinekef406062016-09-29 17:33:13 -07003633 setOwnScrollY(0);
Jason Monk2a6ea9c2017-01-26 11:14:51 -05003634 mStatusBar.resetUserExpandedStates();
Selim Cinek5b1591a2017-07-03 17:05:01 +02003635 clearTemporaryViews();
3636 clearUserLockedViews();
3637 }
3638 }
Selim Cinekf336f4c2014-11-12 16:58:16 +01003639
Selim Cinek5b1591a2017-07-03 17:05:01 +02003640 private void clearUserLockedViews() {
3641 for (int i = 0; i < getChildCount(); i++) {
3642 ExpandableView child = (ExpandableView) getChildAt(i);
3643 if (child instanceof ExpandableNotificationRow) {
3644 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
3645 row.setUserLocked(false);
3646 }
3647 }
3648 }
3649
3650 private void clearTemporaryViews() {
Selim Cinek9dd0d042018-05-14 18:12:42 -07003651 // lets make sure nothing is transient anymore
Rohan Shah8ee53652018-04-05 11:13:50 -07003652 clearTemporaryViewsInGroup(this);
Selim Cinek5b1591a2017-07-03 17:05:01 +02003653 for (int i = 0; i < getChildCount(); i++) {
3654 ExpandableView child = (ExpandableView) getChildAt(i);
3655 if (child instanceof ExpandableNotificationRow) {
3656 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Rohan Shah8ee53652018-04-05 11:13:50 -07003657 clearTemporaryViewsInGroup(row.getChildrenContainer());
Selim Cinekd1395642016-04-28 12:22:42 -07003658 }
Selim Cinek4fe3e472014-07-03 16:32:54 +02003659 }
Selim Cinek1685e632014-04-08 02:27:49 +02003660 }
3661
Rohan Shah8ee53652018-04-05 11:13:50 -07003662 private void clearTemporaryViewsInGroup(ViewGroup viewGroup) {
Selim Cinekd1395642016-04-28 12:22:42 -07003663 while (viewGroup != null && viewGroup.getTransientViewCount() != 0) {
Selim Cinek81f26d32016-05-09 18:54:10 -04003664 viewGroup.removeTransientView(viewGroup.getTransientView(0));
Selim Cinekd1395642016-04-28 12:22:42 -07003665 }
3666 }
3667
Jorim Jaggie4b840d2015-06-30 16:19:17 -07003668 public void onPanelTrackingStarted() {
3669 mPanelTracking = true;
Selim Cinekd5ab6452016-12-08 16:34:00 -08003670 mAmbientState.setPanelTracking(true);
Jorim Jaggie4b840d2015-06-30 16:19:17 -07003671 }
3672 public void onPanelTrackingStopped() {
3673 mPanelTracking = false;
Selim Cinekd5ab6452016-12-08 16:34:00 -08003674 mAmbientState.setPanelTracking(false);
Jorim Jaggie4b840d2015-06-30 16:19:17 -07003675 }
3676
Selim Cinekb24e0a92015-06-09 20:17:30 -07003677 public void resetScrollPosition() {
3678 mScroller.abortAnimation();
Selim Cinekef406062016-09-29 17:33:13 -07003679 setOwnScrollY(0);
Selim Cinekb24e0a92015-06-09 20:17:30 -07003680 }
3681
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +02003682 private void setIsExpanded(boolean isExpanded) {
Selim Cinekcab4a602014-09-03 14:47:57 +02003683 boolean changed = isExpanded != mIsExpanded;
Selim Cinek572bbd42014-04-25 16:43:27 +02003684 mIsExpanded = isExpanded;
Selim Cinek1685e632014-04-08 02:27:49 +02003685 mStackScrollAlgorithm.setIsExpanded(isExpanded);
Selim Cinekcab4a602014-09-03 14:47:57 +02003686 if (changed) {
Selim Cinek9184f9c2016-02-02 17:36:53 -08003687 if (!mIsExpanded) {
3688 mGroupManager.collapseAllGroups();
Selim Cinek5b1591a2017-07-03 17:05:01 +02003689 mExpandHelper.cancelImmediately();
Selim Cinek9184f9c2016-02-02 17:36:53 -08003690 }
Selim Cinekcab4a602014-09-03 14:47:57 +02003691 updateNotificationAnimationStates();
Selim Cinek98713a42015-09-21 15:47:20 +02003692 updateChronometers();
Selim Cinekf3fa6852016-12-20 18:36:02 +01003693 requestChildrenUpdate();
Selim Cinek98713a42015-09-21 15:47:20 +02003694 }
3695 }
3696
3697 private void updateChronometers() {
3698 int childCount = getChildCount();
3699 for (int i = 0; i < childCount; i++) {
3700 updateChronometerForChild(getChildAt(i));
3701 }
3702 }
3703
3704 private void updateChronometerForChild(View child) {
3705 if (child instanceof ExpandableNotificationRow) {
3706 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
3707 row.setChronometerRunning(mIsExpanded);
Selim Cinekcab4a602014-09-03 14:47:57 +02003708 }
Selim Cinek1685e632014-04-08 02:27:49 +02003709 }
3710
Jorim Jaggibe565df2014-04-28 17:51:23 +02003711 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01003712 public void onHeightChanged(ExpandableView view, boolean needsAnimation) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003713 updateContentHeight();
Selim Cinekf7a14c02014-07-07 14:01:46 +02003714 updateScrollPositionOnExpandInBottom(view);
3715 clampScrollPosition();
Lucas Dupin60661a62018-04-12 10:50:13 -07003716 notifyHeightChangeListener(view, needsAnimation);
Selim Cinekbc243a92016-09-27 16:35:13 -07003717 ExpandableNotificationRow row = view instanceof ExpandableNotificationRow
3718 ? (ExpandableNotificationRow) view
3719 : null;
3720 if (row != null && (row == mFirstVisibleBackgroundChild
3721 || row.getNotificationParent() == mFirstVisibleBackgroundChild)) {
3722 updateAlgorithmLayoutMinHeight();
3723 }
Selim Cinekb5605e52015-02-20 18:21:41 +01003724 if (needsAnimation) {
Selim Cinek5bc852a2015-12-21 12:19:09 -08003725 requestAnimationOnViewResize(row);
Selim Cinekb5605e52015-02-20 18:21:41 +01003726 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003727 requestChildrenUpdate();
Jorim Jaggibe565df2014-04-28 17:51:23 +02003728 }
3729
Selim Cineka5e211b2014-08-11 17:35:48 +02003730 @Override
3731 public void onReset(ExpandableView view) {
Selim Cinek51ae05d2014-09-09 15:51:38 +02003732 updateAnimationState(view);
Selim Cinek98713a42015-09-21 15:47:20 +02003733 updateChronometerForChild(view);
Selim Cineka5e211b2014-08-11 17:35:48 +02003734 }
3735
Selim Cinekf7a14c02014-07-07 14:01:46 +02003736 private void updateScrollPositionOnExpandInBottom(ExpandableView view) {
Selim Cinek51d21972017-07-19 17:39:20 -07003737 if (view instanceof ExpandableNotificationRow && !onKeyguard()) {
Selim Cinekf7a14c02014-07-07 14:01:46 +02003738 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekcb9400a2015-06-03 16:56:13 +02003739 if (row.isUserLocked() && row != getFirstChildNotGone()) {
Selim Cinek4e4cac32016-03-11 16:45:52 -08003740 if (row.isSummaryWithChildren()) {
3741 return;
3742 }
Selim Cinekf7a14c02014-07-07 14:01:46 +02003743 // We are actually expanding this view
Selim Cinek4e4cac32016-03-11 16:45:52 -08003744 float endPosition = row.getTranslationY() + row.getActualHeight();
Selim Cinek388df6d2015-10-22 13:25:11 -07003745 if (row.isChildInGroup()) {
Selim Cinek4e4cac32016-03-11 16:45:52 -08003746 endPosition += row.getNotificationParent().getTranslationY();
Selim Cinek388df6d2015-10-22 13:25:11 -07003747 }
Selim Cinekdb167372016-11-17 15:41:17 -08003748 int layoutEnd = mMaxLayoutHeight + (int) mStackTranslation;
Anthony Chen9e05d462017-04-07 10:10:21 -07003749 if (row != mLastVisibleBackgroundChild && mShelf.getVisibility() != GONE) {
Selim Cinekdb167372016-11-17 15:41:17 -08003750 layoutEnd -= mShelf.getIntrinsicHeight() + mPaddingBetweenElements;
3751 }
3752 if (endPosition > layoutEnd) {
3753 setOwnScrollY((int) (mOwnScrollY + endPosition - layoutEnd));
Selim Cinekf7a14c02014-07-07 14:01:46 +02003754 mDisallowScrollingInThisMotion = true;
3755 }
3756 }
3757 }
3758 }
3759
Jorim Jaggibe565df2014-04-28 17:51:23 +02003760 public void setOnHeightChangedListener(
3761 ExpandableView.OnHeightChangedListener mOnHeightChangedListener) {
3762 this.mOnHeightChangedListener = mOnHeightChangedListener;
3763 }
3764
Selim Cinek3a9c10a2014-10-28 14:21:10 +01003765 public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) {
3766 mOnEmptySpaceClickListener = listener;
3767 }
3768
Selim Cinek572bbd42014-04-25 16:43:27 +02003769 public void onChildAnimationFinished() {
Selim Cinek6811d722016-01-19 17:53:12 -08003770 setAnimationRunning(false);
Selim Cinek319bdc42014-05-01 23:01:58 +02003771 requestChildrenUpdate();
Selim Cinek32a59fd32015-06-10 13:54:42 -07003772 runAnimationFinishedRunnables();
Selim Cinek9dd0d042018-05-14 18:12:42 -07003773 clearTransient();
Selim Cinek8fc78752016-07-13 14:34:56 -07003774 clearHeadsUpDisappearRunning();
3775 }
3776
3777 private void clearHeadsUpDisappearRunning() {
3778 for (int i = 0; i < getChildCount(); i++) {
3779 View view = getChildAt(i);
3780 if (view instanceof ExpandableNotificationRow) {
Selim Cinek76e813c2016-07-14 11:16:58 -07003781 ExpandableNotificationRow row = (ExpandableNotificationRow) view;
Selim Cinekcafa87f2016-10-26 17:00:17 -07003782 row.setHeadsUpAnimatingAway(false);
Selim Cinek76e813c2016-07-14 11:16:58 -07003783 if (row.isSummaryWithChildren()) {
3784 for (ExpandableNotificationRow child : row.getNotificationChildren()) {
Selim Cinekcafa87f2016-10-26 17:00:17 -07003785 child.setHeadsUpAnimatingAway(false);
Selim Cinek76e813c2016-07-14 11:16:58 -07003786 }
3787 }
Selim Cinek8fc78752016-07-13 14:34:56 -07003788 }
3789 }
Selim Cinek0fccc722015-07-29 17:04:36 -07003790 }
3791
Selim Cinek9dd0d042018-05-14 18:12:42 -07003792 private void clearTransient() {
3793 for (ExpandableView view : mClearTransientViewsWhenFinished) {
3794 StackStateAnimator.removeTransientView(view);
Selim Cinek0fccc722015-07-29 17:04:36 -07003795 }
Selim Cinek9dd0d042018-05-14 18:12:42 -07003796 mClearTransientViewsWhenFinished.clear();
Selim Cinek32a59fd32015-06-10 13:54:42 -07003797 }
3798
3799 private void runAnimationFinishedRunnables() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07003800 for (Runnable runnable : mAnimationFinishedRunnables) {
3801 runnable.run();
3802 }
3803 mAnimationFinishedRunnables.clear();
Selim Cinek572bbd42014-04-25 16:43:27 +02003804 }
3805
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003806 /**
3807 * See {@link AmbientState#setDimmed}.
3808 */
3809 public void setDimmed(boolean dimmed, boolean animate) {
Selim Cinek8a9308d2017-08-24 09:31:08 -07003810 dimmed &= onKeyguard();
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003811 mAmbientState.setDimmed(dimmed);
Jorim Jaggi75c95042014-05-16 19:09:59 +02003812 if (animate && mAnimationsEnabled) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003813 mDimmedNeedsAnimation = true;
3814 mNeedsAnimation = true;
Selim Cinekd35c2792016-01-21 13:20:57 -08003815 animateDimmed(dimmed);
3816 } else {
3817 setDimAmount(dimmed ? 1.0f : 0.0f);
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003818 }
3819 requestChildrenUpdate();
3820 }
3821
Selim Cinek8a9308d2017-08-24 09:31:08 -07003822 @VisibleForTesting
3823 boolean isDimmed() {
3824 return mAmbientState.isDimmed();
3825 }
3826
Selim Cinekd35c2792016-01-21 13:20:57 -08003827 private void setDimAmount(float dimAmount) {
3828 mDimAmount = dimAmount;
3829 updateBackgroundDimming();
3830 }
3831
3832 private void animateDimmed(boolean dimmed) {
3833 if (mDimAnimator != null) {
3834 mDimAnimator.cancel();
3835 }
3836 float target = dimmed ? 1.0f : 0.0f;
3837 if (target == mDimAmount) {
3838 return;
3839 }
3840 mDimAnimator = TimeAnimator.ofFloat(mDimAmount, target);
3841 mDimAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED);
3842 mDimAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
3843 mDimAnimator.addListener(mDimEndListener);
3844 mDimAnimator.addUpdateListener(mDimUpdateListener);
3845 mDimAnimator.start();
3846 }
3847
Jorim Jaggiae441282014-08-01 02:45:18 +02003848 public void setHideSensitive(boolean hideSensitive, boolean animate) {
3849 if (hideSensitive != mAmbientState.isHideSensitive()) {
3850 int childCount = getChildCount();
3851 for (int i = 0; i < childCount; i++) {
3852 ExpandableView v = (ExpandableView) getChildAt(i);
3853 v.setHideSensitiveForIntrinsicHeight(hideSensitive);
3854 }
3855 mAmbientState.setHideSensitive(hideSensitive);
3856 if (animate && mAnimationsEnabled) {
3857 mHideSensitiveNeedsAnimation = true;
3858 mNeedsAnimation = true;
3859 }
Selim Cinek0b9cf462017-12-07 16:31:03 -08003860 updateContentHeight();
Jorim Jaggiae441282014-08-01 02:45:18 +02003861 requestChildrenUpdate();
3862 }
3863 }
3864
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003865 /**
3866 * See {@link AmbientState#setActivatedChild}.
3867 */
Selim Cineka32ab602014-06-11 15:06:01 +02003868 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003869 mAmbientState.setActivatedChild(activatedChild);
Jorim Jaggi75c95042014-05-16 19:09:59 +02003870 if (mAnimationsEnabled) {
3871 mActivateNeedsAnimation = true;
3872 mNeedsAnimation = true;
3873 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003874 requestChildrenUpdate();
3875 }
3876
Selim Cineka32ab602014-06-11 15:06:01 +02003877 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +02003878 return mAmbientState.getActivatedChild();
3879 }
3880
Selim Cinek572bbd42014-04-25 16:43:27 +02003881 private void applyCurrentState() {
Selim Cinek572bbd42014-04-25 16:43:27 +02003882 mCurrentStackScrollState.apply();
Selim Cinekf4c19962014-05-01 21:55:31 +02003883 if (mListener != null) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09003884 mListener.onChildLocationsChanged();
Selim Cinekf4c19962014-05-01 21:55:31 +02003885 }
Selim Cinek32a59fd32015-06-10 13:54:42 -07003886 runAnimationFinishedRunnables();
Selim Cinekea66ca02016-05-24 13:33:47 -07003887 setAnimationRunning(false);
Selim Cinek6811d722016-01-19 17:53:12 -08003888 updateBackground();
Selim Cinek33223572016-02-19 19:32:22 -08003889 updateViewShadows();
Selim Cinekb0ee18f2017-12-21 16:15:53 -08003890 updateClippingToTopRoundedCorner();
Selim Cinek33223572016-02-19 19:32:22 -08003891 }
3892
3893 private void updateViewShadows() {
3894 // we need to work around an issue where the shadow would not cast between siblings when
3895 // their z difference is between 0 and 0.1
3896
3897 // Lefts first sort by Z difference
3898 for (int i = 0; i < getChildCount(); i++) {
3899 ExpandableView child = (ExpandableView) getChildAt(i);
3900 if (child.getVisibility() != GONE) {
3901 mTmpSortedChildren.add(child);
3902 }
3903 }
3904 Collections.sort(mTmpSortedChildren, mViewPositionComparator);
3905
3906 // Now lets update the shadow for the views
3907 ExpandableView previous = null;
3908 for (int i = 0; i < mTmpSortedChildren.size(); i++) {
3909 ExpandableView expandableView = mTmpSortedChildren.get(i);
3910 float translationZ = expandableView.getTranslationZ();
3911 float otherZ = previous == null ? translationZ : previous.getTranslationZ();
3912 float diff = otherZ - translationZ;
3913 if (diff <= 0.0f || diff >= FakeShadowView.SHADOW_SIBLING_TRESHOLD) {
3914 // There is no fake shadow to be drawn
3915 expandableView.setFakeShadowIntensity(0.0f, 0.0f, 0, 0);
3916 } else {
3917 float yLocation = previous.getTranslationY() + previous.getActualHeight() -
Mady Mellorb0a82462016-04-30 17:31:02 -07003918 expandableView.getTranslationY() - previous.getExtraBottomPadding();
3919 expandableView.setFakeShadowIntensity(
3920 diff / FakeShadowView.SHADOW_SIBLING_TRESHOLD,
Selim Cinek33223572016-02-19 19:32:22 -08003921 previous.getOutlineAlpha(), (int) yLocation,
3922 previous.getOutlineTranslation());
3923 }
3924 previous = expandableView;
3925 }
3926
3927 mTmpSortedChildren.clear();
Selim Cinek572bbd42014-04-25 16:43:27 +02003928 }
3929
Lucas Dupine17ce522017-07-17 15:45:06 -07003930 /**
3931 * Update colors of "dismiss" and "empty shade" views.
3932 *
3933 * @param lightTheme True if light theme should be used.
3934 */
3935 public void updateDecorViews(boolean lightTheme) {
3936 if (lightTheme == mUsingLightTheme) {
3937 return;
3938 }
3939 mUsingLightTheme = lightTheme;
3940 Context context = new ContextThemeWrapper(mContext,
3941 lightTheme ? R.style.Theme_SystemUI_Light : R.style.Theme_SystemUI);
3942 final int textColor = Utils.getColorAttr(context, R.attr.wallpaperTextColor);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04003943 mFooterView.setTextColor(textColor);
Lucas Dupine17ce522017-07-17 15:45:06 -07003944 mEmptyShadeView.setTextColor(textColor);
3945 }
3946
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02003947 public void goToFullShade(long delay) {
Jorim Jaggi60d07c52014-07-31 15:38:21 +02003948 mGoToFullShadeNeedsAnimation = true;
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02003949 mGoToFullShadeDelay = delay;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01003950 mNeedsAnimation = true;
Jorim Jaggi60d07c52014-07-31 15:38:21 +02003951 requestChildrenUpdate();
Selim Cinekc27437b2014-05-14 10:23:33 +02003952 }
3953
Selim Cinek1408eb52014-06-02 14:45:38 +02003954 public void cancelExpandHelper() {
3955 mExpandHelper.cancel();
3956 }
3957
3958 public void setIntrinsicPadding(int intrinsicPadding) {
3959 mIntrinsicPadding = intrinsicPadding;
Selim Cinek1f624952017-06-08 19:11:50 -07003960 mAmbientState.setIntrinsicPadding(intrinsicPadding);
Selim Cinek1408eb52014-06-02 14:45:38 +02003961 }
3962
Jorim Jaggi30c305c2014-07-01 23:34:41 +02003963 public int getIntrinsicPadding() {
3964 return mIntrinsicPadding;
3965 }
3966
Christoph Studer6e3eceb2014-04-01 18:40:27 +02003967 /**
Jorim Jaggi457cc352014-06-02 22:47:42 +02003968 * @return the y position of the first notification
3969 */
3970 public float getNotificationsTopY() {
Selim Cinekd2281152015-04-10 14:37:46 -07003971 return mTopPadding + getStackTranslation();
Jorim Jaggi457cc352014-06-02 22:47:42 +02003972 }
3973
Selim Cinekc0ce82d2014-06-10 13:21:15 +02003974 @Override
3975 public boolean shouldDelayChildPressedState() {
3976 return true;
3977 }
3978
Jorim Jaggi457cc352014-06-02 22:47:42 +02003979 /**
John Spurlockbf370992014-06-17 13:58:31 -04003980 * See {@link AmbientState#setDark}.
3981 */
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01003982 public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) {
Adrian Roos260c1f72017-08-07 15:52:26 +02003983 if (mAmbientState.isDark() == dark) {
3984 return;
3985 }
John Spurlockbf370992014-06-17 13:58:31 -04003986 mAmbientState.setDark(dark);
3987 if (animate && mAnimationsEnabled) {
3988 mDarkNeedsAnimation = true;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01003989 mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation);
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02003990 mNeedsAnimation = true;
Selim Cinek6811d722016-01-19 17:53:12 -08003991 } else {
Lucas Dupin8e9fa2d2018-01-29 15:36:35 -08003992 setDarkAmount(dark ? 1f : 0f);
Selim Cinek6811d722016-01-19 17:53:12 -08003993 updateBackground();
Selim Cinek6811d722016-01-19 17:53:12 -08003994 }
Lucas Dupin8e9fa2d2018-01-29 15:36:35 -08003995 requestChildrenUpdate();
3996 applyCurrentBackgroundBounds();
Anthony Chen3cb3ad92016-12-01 10:58:47 -08003997 updateWillNotDraw();
Adrian Roos7a9551a2017-01-11 12:27:49 -08003998 notifyHeightChangeListener(mShelf);
John Spurlockbf370992014-06-17 13:58:31 -04003999 }
4000
Bill Lin278e7d62018-06-13 18:07:15 +08004001 private void updatePanelTranslation() {
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004002 setTranslationX(mVerticalPanelTranslation + mAntiBurnInOffsetX * mInterpolatedDarkAmount);
Bill Lin278e7d62018-06-13 18:07:15 +08004003 }
4004
4005 public void setVerticalPanelTranslation(float verticalPanelTranslation) {
4006 mVerticalPanelTranslation = verticalPanelTranslation;
4007 updatePanelTranslation();
Lucas Dupin0cd882f2018-01-30 12:19:49 -08004008 }
4009
Anthony Chen3cb3ad92016-12-01 10:58:47 -08004010 /**
4011 * Updates whether or not this Layout will perform its own custom drawing (i.e. whether or
4012 * not {@link #onDraw(Canvas)} is called). This method should be called whenever the
4013 * {@link #mAmbientState}'s dark mode is toggled.
4014 */
4015 private void updateWillNotDraw() {
Lucas Dupind285cf02018-01-18 09:18:23 -08004016 boolean willDraw = mShouldDrawNotificationBackground || DEBUG;
Adrian Roosf0b4f962017-05-25 11:53:11 -07004017 setWillNotDraw(!willDraw);
Anthony Chen3cb3ad92016-12-01 10:58:47 -08004018 }
4019
Lucas Dupind285cf02018-01-18 09:18:23 -08004020 private void setDarkAmount(float darkAmount) {
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004021 setDarkAmount(darkAmount, darkAmount);
4022 }
4023
4024 /**
4025 * Sets the current dark amount.
4026 *
4027 * @param linearDarkAmount The dark amount that follows linear interpoloation in the animation,
4028 * i.e. animates from 0 to 1 or vice-versa in a linear manner.
4029 * @param interpolatedDarkAmount The dark amount that follows the actual interpolation of the
4030 * animation curve.
4031 */
4032 public void setDarkAmount(float linearDarkAmount, float interpolatedDarkAmount) {
4033 mLinearDarkAmount = linearDarkAmount;
4034 mInterpolatedDarkAmount = interpolatedDarkAmount;
Lucas Dupinb561eda2018-04-09 17:25:04 -07004035 boolean wasFullyDark = mAmbientState.isFullyDark();
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004036 mAmbientState.setDarkAmount(interpolatedDarkAmount);
Selim Cinek9bfc7a52018-06-11 16:09:00 -07004037 boolean nowFullyDark = mAmbientState.isFullyDark();
4038 if (nowFullyDark != wasFullyDark) {
Lucas Dupin16cfe452018-02-08 13:14:50 -08004039 updateContentHeight();
Lucas Dupinb561eda2018-04-09 17:25:04 -07004040 DozeParameters dozeParameters = DozeParameters.getInstance(mContext);
Selim Cinek9bfc7a52018-06-11 16:09:00 -07004041 if (nowFullyDark && dozeParameters.shouldControlScreenOff()) {
Lucas Dupinb561eda2018-04-09 17:25:04 -07004042 mShelf.fadeInTranslating();
4043 }
Selim Cinek9bfc7a52018-06-11 16:09:00 -07004044 if (mIconAreaController != null) {
4045 mIconAreaController.setFullyDark(nowFullyDark);
4046 }
Lucas Dupin16cfe452018-02-08 13:14:50 -08004047 }
Lucas Dupin60661a62018-04-12 10:50:13 -07004048 updateAlgorithmHeightAndPadding();
Selim Cinek972123d2016-05-03 14:25:58 -07004049 updateBackgroundDimming();
Bill Lin278e7d62018-06-13 18:07:15 +08004050 updatePanelTranslation();
Lucas Dupinb561eda2018-04-09 17:25:04 -07004051 requestChildrenUpdate();
Selim Cinek972123d2016-05-03 14:25:58 -07004052 }
4053
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004054 public void notifyDarkAnimationStart(boolean dark) {
4055 // We only swap the scaling factor if we're fully dark or fully awake to avoid
4056 // interpolation issues when playing with the power button.
4057 if (mInterpolatedDarkAmount == 0 || mInterpolatedDarkAmount == 1) {
4058 mBackgroundXFactor = dark ? 1.8f : 1.5f;
4059 mDarkXInterpolator = dark
4060 ? Interpolators.FAST_OUT_SLOW_IN_REVERSE
4061 : Interpolators.FAST_OUT_SLOW_IN;
4062 }
Selim Cinek972123d2016-05-03 14:25:58 -07004063 }
4064
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004065 public long getDarkAnimationDuration(boolean dark) {
Lucas Dupin439bd442018-06-12 15:05:28 -07004066 long duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
4067 // Longer animation when sleeping with more than 1 notification
4068 if (dark && getNotGoneChildCount() > 2) {
4069 duration *= 1.2f;
4070 }
Jorim Jaggic4cf07a2018-07-05 18:28:12 +02004071 return duration;
Selim Cinek972123d2016-05-03 14:25:58 -07004072 }
4073
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01004074 private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) {
Selim Cinekbc243a92016-09-27 16:35:13 -07004075 if (screenLocation == null || screenLocation.y < mTopPadding) {
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01004076 return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE;
4077 }
4078 if (screenLocation.y > getBottomMostNotificationBottom()) {
4079 return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW;
4080 }
4081 View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y);
4082 if (child != null) {
4083 return getNotGoneIndex(child);
4084 } else {
4085 return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE;
4086 }
4087 }
4088
4089 private int getNotGoneIndex(View child) {
4090 int count = getChildCount();
4091 int notGoneIndex = 0;
4092 for (int i = 0; i < count; i++) {
4093 View v = getChildAt(i);
4094 if (child == v) {
4095 return notGoneIndex;
4096 }
4097 if (v.getVisibility() != View.GONE) {
4098 notGoneIndex++;
4099 }
4100 }
4101 return -1;
4102 }
4103
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004104 public void setFooterView(@NonNull FooterView footerView) {
Selim Cinek01af3342016-02-09 19:25:31 -08004105 int index = -1;
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004106 if (mFooterView != null) {
4107 index = indexOfChild(mFooterView);
4108 removeView(mFooterView);
Selim Cinek01af3342016-02-09 19:25:31 -08004109 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004110 mFooterView = footerView;
4111 addView(mFooterView, index);
Dan Sandlereceda3d2014-07-21 15:35:01 -04004112 }
4113
Jorim Jaggia2052ea2014-08-05 16:22:30 +02004114 public void setEmptyShadeView(EmptyShadeView emptyShadeView) {
Selim Cinek01af3342016-02-09 19:25:31 -08004115 int index = -1;
4116 if (mEmptyShadeView != null) {
4117 index = indexOfChild(mEmptyShadeView);
4118 removeView(mEmptyShadeView);
4119 }
Jorim Jaggia2052ea2014-08-05 16:22:30 +02004120 mEmptyShadeView = emptyShadeView;
Selim Cinek01af3342016-02-09 19:25:31 -08004121 addView(mEmptyShadeView, index);
Jorim Jaggia2052ea2014-08-05 16:22:30 +02004122 }
4123
4124 public void updateEmptyShadeView(boolean visible) {
Selim Cinekd60ef9e2018-05-16 16:01:05 -07004125 mEmptyShadeView.setVisible(visible, mIsExpanded && mAnimationsEnabled);
Lucas Dupinc9274ff2018-05-09 17:40:20 -07004126
4127 int oldTextRes = mEmptyShadeView.getTextResource();
4128 int newTextRes = mStatusBar.areNotificationsHidden()
4129 ? R.string.dnd_suppressing_shade_text : R.string.empty_shade_text;
4130 if (oldTextRes != newTextRes) {
4131 mEmptyShadeView.setText(newTextRes);
4132 }
Jorim Jaggia2052ea2014-08-05 16:22:30 +02004133 }
4134
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004135 public void updateFooterView(boolean visible, boolean showDismissView) {
4136 if (mFooterView == null) {
Anthony Chen5e3742e2017-04-07 14:28:44 -07004137 return;
4138 }
Selim Cinekd60ef9e2018-05-16 16:01:05 -07004139 boolean animate = mIsExpanded && mAnimationsEnabled;
4140 mFooterView.setVisible(visible, animate);
4141 mFooterView.setSecondaryVisible(showDismissView, animate);
Dan Sandlereceda3d2014-07-21 15:35:01 -04004142 }
4143
4144 public void setDismissAllInProgress(boolean dismissAllInProgress) {
4145 mDismissAllInProgress = dismissAllInProgress;
Selim Cinek9c17b772015-07-07 20:37:09 -07004146 mAmbientState.setDismissAllInProgress(dismissAllInProgress);
Selim Cinek9c17b772015-07-07 20:37:09 -07004147 handleDismissAllClipping();
4148 }
4149
4150 private void handleDismissAllClipping() {
4151 final int count = getChildCount();
4152 boolean previousChildWillBeDismissed = false;
4153 for (int i = 0; i < count; i++) {
4154 ExpandableView child = (ExpandableView) getChildAt(i);
4155 if (child.getVisibility() == GONE) {
4156 continue;
4157 }
4158 if (mDismissAllInProgress && previousChildWillBeDismissed) {
4159 child.setMinClipTopAmount(child.getClipTopAmount());
4160 } else {
4161 child.setMinClipTopAmount(0);
4162 }
4163 previousChildWillBeDismissed = canChildBeDismissed(child);
4164 }
Selim Cineka272dfe2015-02-20 18:12:28 +01004165 }
4166
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004167 public boolean isFooterViewNotGone() {
4168 return mFooterView != null
4169 && mFooterView.getVisibility() != View.GONE
4170 && !mFooterView.willBeGone();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02004171 }
4172
Selim Cinek38475442018-05-18 11:11:46 -07004173 public boolean isFooterViewContentVisible() {
4174 return mFooterView != null && mFooterView.isContentVisible();
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02004175 }
4176
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004177 public int getFooterViewHeight() {
4178 return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements;
Jorim Jaggi4b04a3a2014-07-28 17:43:56 +02004179 }
4180
Jorim Jaggi0cce70c2014-11-04 16:13:41 +01004181 public int getEmptyShadeViewHeight() {
4182 return mEmptyShadeView.getHeight();
4183 }
4184
Jorim Jaggie0640dd2014-08-05 23:12:40 +02004185 public float getBottomMostNotificationBottom() {
4186 final int count = getChildCount();
4187 float max = 0;
4188 for (int childIdx = 0; childIdx < count; childIdx++) {
4189 ExpandableView child = (ExpandableView) getChildAt(childIdx);
4190 if (child.getVisibility() == GONE) {
4191 continue;
4192 }
Selim Cineka686b2c2016-10-26 13:58:27 -07004193 float bottom = child.getTranslationY() + child.getActualHeight()
4194 - child.getClipBottomAmount();
Jorim Jaggie0640dd2014-08-05 23:12:40 +02004195 if (bottom > max) {
4196 max = bottom;
4197 }
4198 }
Selim Cinekd2281152015-04-10 14:37:46 -07004199 return max + getStackTranslation();
Jorim Jaggie0640dd2014-08-05 23:12:40 +02004200 }
4201
Jason Monk2a6ea9c2017-01-26 11:14:51 -05004202 public void setStatusBar(StatusBar statusBar) {
4203 this.mStatusBar = statusBar;
Selim Cinek19c8c702014-08-25 22:09:19 +02004204 }
4205
Selim Cinekb5605e52015-02-20 18:21:41 +01004206 public void setGroupManager(NotificationGroupManager groupManager) {
4207 this.mGroupManager = groupManager;
4208 }
4209
Selim Cinekd9acca52014-09-01 22:33:25 +02004210 public void onGoToKeyguard() {
Selim Cinek379ff8f2015-02-20 17:03:16 +01004211 requestAnimateEverything();
4212 }
4213
4214 private void requestAnimateEverything() {
Selim Cinekd9acca52014-09-01 22:33:25 +02004215 if (mIsExpanded && mAnimationsEnabled) {
4216 mEverythingNeedsAnimation = true;
Selim Cinek379ff8f2015-02-20 17:03:16 +01004217 mNeedsAnimation = true;
Selim Cinekd9acca52014-09-01 22:33:25 +02004218 requestChildrenUpdate();
4219 }
4220 }
4221
Selim Cinek04fb2582015-06-02 19:58:09 +02004222 public boolean isBelowLastNotification(float touchX, float touchY) {
Selim Cinekabf60bb2015-02-20 17:36:10 +01004223 int childCount = getChildCount();
4224 for (int i = childCount - 1; i >= 0; i--) {
4225 ExpandableView child = (ExpandableView) getChildAt(i);
4226 if (child.getVisibility() != View.GONE) {
4227 float childTop = child.getY();
4228 if (childTop > touchY) {
4229 // we are above a notification entirely let's abort
4230 return false;
4231 }
Selim Cineka686b2c2016-10-26 13:58:27 -07004232 boolean belowChild = touchY > childTop + child.getActualHeight()
4233 - child.getClipBottomAmount();
Julia Reynoldsed1c9af2018-03-21 15:21:09 -04004234 if (child == mFooterView) {
4235 if(!belowChild && !mFooterView.isOnEmptySpace(touchX - mFooterView.getX(),
Selim Cinekabf60bb2015-02-20 17:36:10 +01004236 touchY - childTop)) {
4237 // We clicked on the dismiss button
4238 return false;
4239 }
4240 } else if (child == mEmptyShadeView) {
4241 // We arrived at the empty shade view, for which we accept all clicks
4242 return true;
4243 } else if (!belowChild){
4244 // We are on a child
4245 return false;
4246 }
4247 }
Selim Cinek3a9c10a2014-10-28 14:21:10 +01004248 }
Selim Cinek04fb2582015-06-02 19:58:09 +02004249 return touchY > mTopPadding + mStackTranslation;
Selim Cinek3a9c10a2014-10-28 14:21:10 +01004250 }
4251
Selim Cinekb5605e52015-02-20 18:21:41 +01004252 @Override
4253 public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) {
Selim Cinek1b2a05e2016-04-28 14:20:39 -07004254 boolean animated = !mGroupExpandedForMeasure && mAnimationsEnabled
4255 && (mIsExpanded || changedRow.isPinned());
Selim Cinekb5605e52015-02-20 18:21:41 +01004256 if (animated) {
4257 mExpandedGroupView = changedRow;
4258 mNeedsAnimation = true;
4259 }
4260 changedRow.setChildrenExpanded(expanded, animated);
Selim Cinek1b2a05e2016-04-28 14:20:39 -07004261 if (!mGroupExpandedForMeasure) {
4262 onHeightChanged(changedRow, false /* needsAnimation */);
4263 }
Mady Mellorb0a82462016-04-30 17:31:02 -07004264 runAfterAnimationFinished(new Runnable() {
4265 @Override
4266 public void run() {
4267 changedRow.onFinishedExpansionChange();
4268 }
4269 });
Selim Cinekb5605e52015-02-20 18:21:41 +01004270 }
4271
4272 @Override
Selim Cinekb5605e52015-02-20 18:21:41 +01004273 public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05004274 mStatusBar.requestNotificationUpdate();
Selim Cinekef5127e2015-12-21 16:55:58 -08004275 }
4276
Selim Cinekc22fff62016-05-20 12:44:30 -07004277 /** @hide */
4278 @Override
4279 public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
4280 super.onInitializeAccessibilityEventInternal(event);
4281 event.setScrollable(mScrollable);
4282 event.setScrollX(mScrollX);
4283 event.setScrollY(mOwnScrollY);
4284 event.setMaxScrollX(mScrollX);
4285 event.setMaxScrollY(getScrollRange());
4286 }
4287
4288 @Override
4289 public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
4290 super.onInitializeAccessibilityNodeInfoInternal(info);
Selim Cinekef406062016-09-29 17:33:13 -07004291 if (mScrollable) {
Selim Cinekc22fff62016-05-20 12:44:30 -07004292 info.setScrollable(true);
Selim Cinekef406062016-09-29 17:33:13 -07004293 if (mBackwardScrollable) {
Selim Cinekc22fff62016-05-20 12:44:30 -07004294 info.addAction(
4295 AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
4296 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_UP);
4297 }
Selim Cinekef406062016-09-29 17:33:13 -07004298 if (mForwardScrollable) {
Selim Cinekc22fff62016-05-20 12:44:30 -07004299 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
4300 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_DOWN);
4301 }
4302 }
Selim Cinek41fe89a2016-06-02 15:27:56 -07004303 // Talkback only listenes to scroll events of certain classes, let's make us a scrollview
4304 info.setClassName(ScrollView.class.getName());
Selim Cinekc22fff62016-05-20 12:44:30 -07004305 }
4306
4307 /** @hide */
4308 @Override
4309 public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
4310 if (super.performAccessibilityActionInternal(action, arguments)) {
4311 return true;
4312 }
4313 if (!isEnabled()) {
4314 return false;
4315 }
4316 int direction = -1;
4317 switch (action) {
4318 case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
4319 // fall through
4320 case android.R.id.accessibilityActionScrollDown:
4321 direction = 1;
4322 // fall through
4323 case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
4324 // fall through
4325 case android.R.id.accessibilityActionScrollUp:
4326 final int viewportHeight = getHeight() - mPaddingBottom - mTopPadding - mPaddingTop
Selim Cinekad7fac02016-10-18 17:09:15 -07004327 - mShelf.getIntrinsicHeight();
Selim Cinekc22fff62016-05-20 12:44:30 -07004328 final int targetScrollY = Math.max(0,
4329 Math.min(mOwnScrollY + direction * viewportHeight, getScrollRange()));
4330 if (targetScrollY != mOwnScrollY) {
4331 mScroller.startScroll(mScrollX, mOwnScrollY, 0, targetScrollY - mOwnScrollY);
Selim Cinek9212de82017-02-06 16:04:28 -08004332 animateScroll();
Selim Cinekc22fff62016-05-20 12:44:30 -07004333 return true;
4334 }
4335 break;
4336 }
4337 return false;
4338 }
4339
Selim Cinekef5127e2015-12-21 16:55:58 -08004340 @Override
Selim Cinek2a739342016-03-17 10:28:55 -07004341 public void onGroupsChanged() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -05004342 mStatusBar.requestNotificationUpdate();
Selim Cinekb5605e52015-02-20 18:21:41 +01004343 }
4344
4345 public void generateChildOrderChangedEvent() {
4346 if (mIsExpanded && mAnimationsEnabled) {
4347 mGenerateChildOrderChangedEvent = true;
4348 mNeedsAnimation = true;
4349 requestChildrenUpdate();
4350 }
4351 }
4352
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09004353 @Override
4354 public int getContainerChildCount() {
4355 return getChildCount();
4356 }
4357
4358 @Override
4359 public View getContainerChildAt(int i) {
4360 return getChildAt(i);
4361 }
4362
4363 @Override
4364 public void removeContainerView(View v) {
4365 removeView(v);
4366 }
4367
4368 @Override
4369 public void addContainerView(View v) {
4370 addView(v);
4371 }
4372
Selim Cinek684a4422015-04-15 16:18:39 -07004373 public void runAfterAnimationFinished(Runnable runnable) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004374 mAnimationFinishedRunnables.add(runnable);
4375 }
4376
yoshiki iguchi4e30e762018-02-06 12:09:23 +09004377 public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004378 mHeadsUpManager = headsUpManager;
4379 mAmbientState.setHeadsUpManager(headsUpManager);
Selim Cinek29aab962018-02-27 17:05:45 -08004380 mHeadsUpManager.addListener(mRoundnessManager);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004381 }
4382
4383 public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) {
Selim Cinek5cf1d052017-06-01 17:36:46 -07004384 if (mAnimationsEnabled && (isHeadsUp || mHeadsUpGoingAwayAnimationsAllowed)) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004385 mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp));
4386 mNeedsAnimation = true;
Selim Cinek73cf02a2016-06-17 13:08:00 -07004387 if (!mIsExpanded && !isHeadsUp) {
Selim Cinekcafa87f2016-10-26 17:00:17 -07004388 row.setHeadsUpAnimatingAway(true);
Selim Cinek73cf02a2016-06-17 13:08:00 -07004389 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004390 requestChildrenUpdate();
4391 }
4392 }
4393
4394 public void setShadeExpanded(boolean shadeExpanded) {
4395 mAmbientState.setShadeExpanded(shadeExpanded);
Selim Cineka59ecc32015-04-07 10:51:49 -07004396 mStateAnimator.setShadeExpanded(shadeExpanded);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004397 }
4398
Selim Cineka59ecc32015-04-07 10:51:49 -07004399 /**
4400 * Set the boundary for the bottom heads up position. The heads up will always be above this
4401 * position.
4402 *
4403 * @param height the height of the screen
4404 * @param bottomBarHeight the height of the bar on the bottom
4405 */
4406 public void setHeadsUpBoundaries(int height, int bottomBarHeight) {
4407 mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight);
4408 mStateAnimator.setHeadsUpAppearHeightBottom(height);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004409 requestChildrenUpdate();
4410 }
4411
Selim Cinekaa9db1f2018-02-27 17:35:47 -08004412 public void setTrackingHeadsUp(ExpandableNotificationRow row) {
4413 mTrackingHeadsUp = row != null;
4414 mRoundnessManager.setTrackingHeadsUp(row);
Selim Cinekb8f09cf2015-03-16 17:09:28 -07004415 }
4416
Selim Cinekaac93252015-04-14 20:04:12 -07004417 public void setScrimController(ScrimController scrimController) {
4418 mScrimController = scrimController;
Lucas Dupin8da8f2e92017-04-21 14:02:16 -07004419 mScrimController.setScrimBehindChangeRunnable(this::updateBackgroundDimming);
Selim Cinekaac93252015-04-14 20:04:12 -07004420 }
4421
Selim Cinekbbc580b2015-06-03 14:11:03 +02004422 public void forceNoOverlappingRendering(boolean force) {
4423 mForceNoOverlappingRendering = force;
4424 }
4425
4426 @Override
4427 public boolean hasOverlappingRendering() {
4428 return !mForceNoOverlappingRendering && super.hasOverlappingRendering();
4429 }
4430
Selim Cinek6811d722016-01-19 17:53:12 -08004431 public void setAnimationRunning(boolean animationRunning) {
4432 if (animationRunning != mAnimationRunning) {
4433 if (animationRunning) {
Selim Cinekc383fd02016-10-21 15:31:26 -07004434 getViewTreeObserver().addOnPreDrawListener(mRunningAnimationUpdater);
Selim Cinek6811d722016-01-19 17:53:12 -08004435 } else {
Selim Cinekc383fd02016-10-21 15:31:26 -07004436 getViewTreeObserver().removeOnPreDrawListener(mRunningAnimationUpdater);
Selim Cinek6811d722016-01-19 17:53:12 -08004437 }
4438 mAnimationRunning = animationRunning;
Selim Cinek33223572016-02-19 19:32:22 -08004439 updateContinuousShadowDrawing();
Selim Cinek6811d722016-01-19 17:53:12 -08004440 }
4441 }
4442
Selim Cinek3776fe02016-02-04 13:32:43 -08004443 public boolean isExpanded() {
4444 return mIsExpanded;
4445 }
4446
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07004447 public void setPulsing(boolean pulsing, boolean animated) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +09004448 if (!mPulsing && !pulsing) {
Adrian Roosb2a87292017-02-13 15:05:03 +01004449 return;
4450 }
Selim Cinekcd5b22f2016-03-08 16:15:41 -08004451 mPulsing = pulsing;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07004452 mNeedingPulseAnimation = animated ? getFirstChildNotGone() : null;
Selim Cinekebf42342017-07-13 15:46:10 +02004453 mAmbientState.setPulsing(pulsing);
Selim Cinekcd5b22f2016-03-08 16:15:41 -08004454 updateNotificationAnimationStates();
Lucas Dupin6bf7b642018-01-22 18:56:24 -08004455 updateAlgorithmHeightAndPadding();
Adrian Roos7a9551a2017-01-11 12:27:49 -08004456 updateContentHeight();
Adrian Roosd83e9992017-03-16 15:17:57 -07004457 requestChildrenUpdate();
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07004458 notifyHeightChangeListener(null, animated);
4459 mNeedsAnimation |= animated;
4460 }
4461
4462 private void generatePulsingAnimationEvent() {
4463 if (mNeedingPulseAnimation != null) {
4464 int type = mPulsing ? AnimationEvent.ANIMATION_TYPE_PULSE_APPEAR
4465 : AnimationEvent.ANIMATION_TYPE_PULSE_DISAPPEAR;
4466 mAnimationEvents.add(new AnimationEvent(mNeedingPulseAnimation, type));
4467 mNeedingPulseAnimation = null;
4468 }
Selim Cinekcd5b22f2016-03-08 16:15:41 -08004469 }
4470
Selim Cinek07304f5222016-05-19 18:31:36 -07004471 public void setFadingOut(boolean fadingOut) {
4472 if (fadingOut != mFadingOut) {
4473 mFadingOut = fadingOut;
4474 updateFadingState();
Selim Cinek31d37b92016-04-26 09:56:42 -07004475 }
4476 }
4477
Selim Cinek48ff9b42016-11-09 19:31:51 -08004478 public void setParentNotFullyVisible(boolean parentNotFullyVisible) {
4479 if (mScrimController == null) {
4480 // we're not set up yet.
4481 return;
4482 }
4483 if (parentNotFullyVisible != mParentNotFullyVisible) {
4484 mParentNotFullyVisible = parentNotFullyVisible;
Selim Cinek07304f5222016-05-19 18:31:36 -07004485 updateFadingState();
4486 }
4487 }
4488
4489 private void updateFadingState() {
Selim Cinek9bfba9c2016-08-08 15:20:06 -07004490 applyCurrentBackgroundBounds();
Selim Cinek07304f5222016-05-19 18:31:36 -07004491 updateSrcDrawing();
4492 }
4493
Selim Cinek31d37b92016-04-26 09:56:42 -07004494 @Override
4495 public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) {
4496 super.setAlpha(alpha);
Selim Cinek07304f5222016-05-19 18:31:36 -07004497 setFadingOut(alpha != 1.0f);
Selim Cinek31d37b92016-04-26 09:56:42 -07004498 }
4499
Selim Cinekbc243a92016-09-27 16:35:13 -07004500 public void setQsExpanded(boolean qsExpanded) {
4501 mQsExpanded = qsExpanded;
4502 updateAlgorithmLayoutMinHeight();
Riddle Hsu065c01c2018-05-10 23:14:19 +08004503 updateScrollability();
Selim Cinekbc243a92016-09-27 16:35:13 -07004504 }
4505
shawnlin8e4e92c2018-04-12 18:47:24 +08004506 public void setQsExpansionFraction(float qsExpansionFraction) {
4507 mQsExpansionFraction = qsExpansionFraction;
4508 }
4509
Selim Cinekef406062016-09-29 17:33:13 -07004510 public void setOwnScrollY(int ownScrollY) {
4511 if (ownScrollY != mOwnScrollY) {
Selim Cinek9212de82017-02-06 16:04:28 -08004512 // We still want to call the normal scrolled changed for accessibility reasons
4513 onScrollChanged(mScrollX, ownScrollY, mScrollX, mOwnScrollY);
Selim Cinekef406062016-09-29 17:33:13 -07004514 mOwnScrollY = ownScrollY;
4515 updateForwardAndBackwardScrollability();
Selim Cinek9212de82017-02-06 16:04:28 -08004516 requestChildrenUpdate();
Selim Cinekef406062016-09-29 17:33:13 -07004517 }
4518 }
4519
Selim Cinek281c2022016-10-13 19:14:43 -07004520 public void setShelf(NotificationShelf shelf) {
Selim Cinek281c2022016-10-13 19:14:43 -07004521 int index = -1;
4522 if (mShelf != null) {
4523 index = indexOfChild(mShelf);
4524 removeView(mShelf);
4525 }
Selim Cinek0e8d77e2016-11-29 10:35:42 -08004526 mShelf = shelf;
Selim Cinek281c2022016-10-13 19:14:43 -07004527 addView(mShelf, index);
4528 mAmbientState.setShelf(shelf);
Selim Cinekeccb5de2016-10-28 15:04:05 -07004529 mStateAnimator.setShelf(shelf);
Selim Cinekc383fd02016-10-21 15:31:26 -07004530 shelf.bind(mAmbientState, this);
Selim Cinek281c2022016-10-13 19:14:43 -07004531 }
4532
4533 public NotificationShelf getNotificationShelf() {
4534 return mShelf;
4535 }
4536
Selim Cinekad7fac02016-10-18 17:09:15 -07004537 public void setMaxDisplayedNotifications(int maxDisplayedNotifications) {
4538 if (mMaxDisplayedNotifications != maxDisplayedNotifications) {
4539 mMaxDisplayedNotifications = maxDisplayedNotifications;
4540 updateContentHeight();
4541 notifyHeightChangeListener(mShelf);
4542 }
4543 }
4544
shawnlin8e4e92c2018-04-12 18:47:24 +08004545 public void setShouldShowShelfOnly(boolean shouldShowShelfOnly) {
4546 mShouldShowShelfOnly = shouldShowShelfOnly;
4547 updateAlgorithmLayoutMinHeight();
4548 }
4549
Selim Cinek48ff9b42016-11-09 19:31:51 -08004550 public int getMinExpansionHeight() {
Selim Cinekd127d792016-11-01 19:11:41 -07004551 return mShelf.getIntrinsicHeight() - (mShelf.getIntrinsicHeight() - mStatusBarHeight) / 2;
Selim Cinek48ff9b42016-11-09 19:31:51 -08004552 }
4553
Selim Cinekcafa87f2016-10-26 17:00:17 -07004554 public void setInHeadsUpPinnedMode(boolean inHeadsUpPinnedMode) {
4555 mInHeadsUpPinnedMode = inHeadsUpPinnedMode;
4556 updateClipping();
4557 }
4558
4559 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
4560 mHeadsUpAnimatingAway = headsUpAnimatingAway;
4561 updateClipping();
4562 }
4563
Selim Cinek355652a2016-12-07 13:32:12 -08004564 public void setStatusBarState(int statusBarState) {
4565 mStatusBarState = statusBarState;
4566 mAmbientState.setStatusBarState(statusBarState);
4567 }
4568
Selim Cinekd5ab6452016-12-08 16:34:00 -08004569 public void setExpandingVelocity(float expandingVelocity) {
4570 mAmbientState.setExpandingVelocity(expandingVelocity);
4571 }
4572
Selim Cinekfcff4c62016-12-27 14:26:06 +01004573 public float getOpeningHeight() {
4574 if (mEmptyShadeView.getVisibility() == GONE) {
4575 return getMinExpansionHeight();
4576 } else {
4577 return getAppearEndPosition();
4578 }
4579 }
4580
4581 public void setIsFullWidth(boolean isFullWidth) {
4582 mAmbientState.setPanelFullWidth(isFullWidth);
4583 }
4584
Selim Cinekec29d342017-05-05 18:31:49 -07004585 public void setUnlockHintRunning(boolean running) {
4586 mAmbientState.setUnlockHintRunning(running);
4587 }
4588
Selim Cinek5cf1d052017-06-01 17:36:46 -07004589 public void setQsCustomizerShowing(boolean isShowing) {
4590 mAmbientState.setQsCustomizerShowing(isShowing);
4591 requestChildrenUpdate();
4592 }
4593
4594 public void setHeadsUpGoingAwayAnimationsAllowed(boolean headsUpGoingAwayAnimationsAllowed) {
4595 mHeadsUpGoingAwayAnimationsAllowed = headsUpGoingAwayAnimationsAllowed;
4596 }
4597
Lucas Dupin0cd882f2018-01-30 12:19:49 -08004598 public void setAntiBurnInOffsetX(int antiBurnInOffsetX) {
4599 mAntiBurnInOffsetX = antiBurnInOffsetX;
Bill Lin278e7d62018-06-13 18:07:15 +08004600 updatePanelTranslation();
Adrian Roosdc747bd2017-06-01 16:09:15 -07004601 }
4602
Selim Cinek707e2072017-06-30 18:32:40 +02004603 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
4604 pw.println(String.format("[%s: pulsing=%s qsCustomizerShowing=%s visibility=%s"
shawnlin8e4e92c2018-04-12 18:47:24 +08004605 + " alpha:%f scrollY:%d maxTopPadding:%d showShelfOnly=%s"
4606 + " qsExpandFraction=%f]",
Selim Cinek707e2072017-06-30 18:32:40 +02004607 this.getClass().getSimpleName(),
yoshiki iguchi4e30e762018-02-06 12:09:23 +09004608 mPulsing ? "T":"f",
Selim Cinek707e2072017-06-30 18:32:40 +02004609 mAmbientState.isQsCustomizerShowing() ? "T":"f",
4610 getVisibility() == View.VISIBLE ? "visible"
4611 : getVisibility() == View.GONE ? "gone"
4612 : "invisible",
4613 getAlpha(),
shawnlin8e4e92c2018-04-12 18:47:24 +08004614 mAmbientState.getScrollY(),
4615 mMaxTopPadding,
4616 mShouldShowShelfOnly ? "T":"f",
4617 mQsExpansionFraction));
Selim Cinek707e2072017-06-30 18:32:40 +02004618 }
4619
Lucas Dupin16cfe452018-02-08 13:14:50 -08004620 public boolean isFullyDark() {
4621 return mAmbientState.isFullyDark();
4622 }
4623
Selim Cinek7103fd42016-05-09 22:22:33 -04004624 /**
Selim Cinekaa9db1f2018-02-27 17:35:47 -08004625 * Add a listener whenever the expanded height changes. The first value passed as an argument
4626 * is the expanded height and the second one is the appearFraction.
4627 *
4628 * @param listener the listener to notify.
4629 */
4630 public void addOnExpandedHeightListener(BiConsumer<Float, Float> listener) {
4631 mExpandedHeightListeners.add(listener);
4632 }
4633
4634 /**
Selim Cinek60ffea62018-03-22 13:16:44 -07004635 * Stop a listener from listening to the expandedHeight.
4636 */
4637 public void removeOnExpandedHeightListener(BiConsumer<Float, Float> listener) {
4638 mExpandedHeightListeners.remove(listener);
4639 }
4640
Selim Cinekf0c79e12018-05-14 17:17:31 -07004641 public void setHeadsUpAppearanceController(
4642 HeadsUpAppearanceController headsUpAppearanceController) {
4643 mHeadsUpAppearanceController = headsUpAppearanceController;
4644 }
4645
Selim Cinek9bfc7a52018-06-11 16:09:00 -07004646 public void setIconAreaController(NotificationIconAreaController controller) {
4647 mIconAreaController = controller;
4648 }
4649
Selim Cinek60ffea62018-03-22 13:16:44 -07004650 /**
Selim Cinek3a9c10a2014-10-28 14:21:10 +01004651 * A listener that is notified when the empty space below the notifications is clicked on
4652 */
4653 public interface OnEmptySpaceClickListener {
Anthony Chen3cb3ad92016-12-01 10:58:47 -08004654 void onEmptySpaceClicked(float x, float y);
Selim Cinek3a9c10a2014-10-28 14:21:10 +01004655 }
4656
4657 /**
Jorim Jaggi290600a2014-05-30 17:02:20 +02004658 * A listener that gets notified when the overscroll at the top has changed.
4659 */
4660 public interface OnOverscrollTopChangedListener {
Jorim Jaggi475b21d2014-07-01 18:13:24 +02004661
4662 /**
4663 * Notifies a listener that the overscroll has changed.
4664 *
4665 * @param amount the amount of overscroll, in pixels
4666 * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an
4667 * unrubberbanded motion to directly expand overscroll view (e.g expand
4668 * QS)
4669 */
Anthony Chen3cb3ad92016-12-01 10:58:47 -08004670 void onOverscrollTopChanged(float amount, boolean isRubberbanded);
Selim Cinek1408eb52014-06-02 14:45:38 +02004671
4672 /**
4673 * Notify a listener that the scroller wants to escape from the scrolling motion and
4674 * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS)
4675 *
4676 * @param velocity The velocity that the Scroller had when over flinging
4677 * @param open Should the fling open or close the overscroll view.
4678 */
Anthony Chen3cb3ad92016-12-01 10:58:47 -08004679 void flingTopOverscroll(float velocity, boolean open);
Jorim Jaggi290600a2014-05-30 17:02:20 +02004680 }
4681
Mady Mellor95d743c2017-01-10 12:05:27 -08004682 private class NotificationSwipeHelper extends SwipeHelper
4683 implements NotificationSwipeActionHelper {
4684 private static final long COVER_MENU_DELAY = 4000;
Mady Mellor97c8df42016-03-22 18:09:39 -07004685 private Runnable mFalsingCheck;
Mady Mellor4b80b102016-01-22 08:03:58 -08004686 private Handler mHandler;
Mady Mellor4b80b102016-01-22 08:03:58 -08004687
4688 public NotificationSwipeHelper(int swipeDirection, Callback callback, Context context) {
4689 super(swipeDirection, callback, context);
4690 mHandler = new Handler();
Mady Mellor97c8df42016-03-22 18:09:39 -07004691 mFalsingCheck = new Runnable() {
4692 @Override
4693 public void run() {
Mady Mellor95d743c2017-01-10 12:05:27 -08004694 resetExposedMenuView(true /* animate */, true /* force */);
Mady Mellor97c8df42016-03-22 18:09:39 -07004695 }
4696 };
Mady Mellor4b80b102016-01-22 08:03:58 -08004697 }
4698
4699 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -08004700 public void onDownUpdate(View currView, MotionEvent ev) {
Mady Mellor4b80b102016-01-22 08:03:58 -08004701 mTranslatingParentView = currView;
Mady Mellor95d743c2017-01-10 12:05:27 -08004702 if (mCurrMenuRow != null) {
4703 mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
Mady Mellor3a5e8dd2016-03-12 00:13:23 +00004704 }
Mady Mellor89e15ec2017-06-28 17:08:21 -07004705 mCurrMenuRow = null;
Mady Mellor97c8df42016-03-22 18:09:39 -07004706 mHandler.removeCallbacks(mFalsingCheck);
Mady Mellor4b80b102016-01-22 08:03:58 -08004707
Mady Mellor95d743c2017-01-10 12:05:27 -08004708 // Slide back any notifications that might be showing a menu
4709 resetExposedMenuView(true /* animate */, false /* force */);
Mady Mellor4b80b102016-01-22 08:03:58 -08004710
4711 if (currView instanceof ExpandableNotificationRow) {
Mady Mellor95d743c2017-01-10 12:05:27 -08004712 ExpandableNotificationRow row = (ExpandableNotificationRow) currView;
4713 mCurrMenuRow = row.createMenu();
4714 mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this);
4715 mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this);
Mady Mellor89e15ec2017-06-28 17:08:21 -07004716 mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
Mady Mellor4b80b102016-01-22 08:03:58 -08004717 }
Mady Mellor4b80b102016-01-22 08:03:58 -08004718 }
4719
4720 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -08004721 public void onMoveUpdate(View view, MotionEvent ev, float translation, float delta) {
Mady Mellor97c8df42016-03-22 18:09:39 -07004722 mHandler.removeCallbacks(mFalsingCheck);
Mady Mellor95d743c2017-01-10 12:05:27 -08004723 if (mCurrMenuRow != null) {
4724 mCurrMenuRow.onTouchEvent(view, ev, 0 /* velocity */);
Mady Mellor4b80b102016-01-22 08:03:58 -08004725 }
Mady Mellor95d743c2017-01-10 12:05:27 -08004726 }
Mady Mellor4b80b102016-01-22 08:03:58 -08004727
Mady Mellor95d743c2017-01-10 12:05:27 -08004728 @Override
4729 public boolean handleUpEvent(MotionEvent ev, View animView, float velocity,
4730 float translation) {
4731 if (mCurrMenuRow != null) {
4732 return mCurrMenuRow.onTouchEvent(animView, ev, velocity);
Mady Mellor4b80b102016-01-22 08:03:58 -08004733 }
Mady Mellor95d743c2017-01-10 12:05:27 -08004734 return false;
Mady Mellor4b80b102016-01-22 08:03:58 -08004735 }
4736
4737 @Override
Mady Mellordc6c97d2016-03-31 14:18:35 -07004738 public void dismissChild(final View view, float velocity,
4739 boolean useAccelerateInterpolator) {
4740 super.dismissChild(view, velocity, useAccelerateInterpolator);
Selim Cinekd1395642016-04-28 12:22:42 -07004741 if (mIsExpanded) {
4742 // We don't want to quick-dismiss when it's a heads up as this might lead to closing
4743 // of the panel early.
Rohan Shah524cf7b2018-03-15 14:40:02 -07004744 handleChildViewDismissed(view);
Selim Cinekd1395642016-04-28 12:22:42 -07004745 }
Eliot Courtney47098cb2017-10-18 17:30:30 +09004746 mStatusBar.getGutsManager().closeAndSaveGuts(true /* removeLeavebehind */,
4747 false /* force */, false /* removeControls */, -1 /* x */, -1 /* y */,
4748 false /* resetMenu */);
Mady Mellor95d743c2017-01-10 12:05:27 -08004749 handleMenuCoveredOrDismissed();
Mady Mellor4b80b102016-01-22 08:03:58 -08004750 }
4751
4752 @Override
4753 public void snapChild(final View animView, final float targetLeft, float velocity) {
Mady Mellor3a5e8dd2016-03-12 00:13:23 +00004754 super.snapChild(animView, targetLeft, velocity);
4755 onDragCancelled(animView);
4756 if (targetLeft == 0) {
Mady Mellor95d743c2017-01-10 12:05:27 -08004757 handleMenuCoveredOrDismissed();
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004758 }
4759 }
Mady Mellor3a5e8dd2016-03-12 00:13:23 +00004760
4761 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -08004762 public void snooze(StatusBarNotification sbn, SnoozeOption snoozeOption) {
4763 mStatusBar.setNotificationSnoozed(sbn, snoozeOption);
Mady Mellor3a5e8dd2016-03-12 00:13:23 +00004764 }
4765
Mady Mellorbd707492017-05-10 17:51:25 -07004766 public boolean isFalseGesture(MotionEvent ev) {
4767 return super.isFalseGesture(ev);
4768 }
4769
Mady Mellor95d743c2017-01-10 12:05:27 -08004770 private void handleMenuCoveredOrDismissed() {
4771 if (mMenuExposedView != null && mMenuExposedView == mTranslatingParentView) {
4772 mMenuExposedView = null;
Mady Mellor3a5e8dd2016-03-12 00:13:23 +00004773 }
4774 }
4775
Mady Mellor4b80b102016-01-22 08:03:58 -08004776 @Override
Mady Mellor4b80b102016-01-22 08:03:58 -08004777 public Animator getViewTranslationAnimator(View v, float target,
4778 AnimatorUpdateListener listener) {
Mady Mellor9c2c4962016-04-05 10:43:08 -07004779 if (v instanceof ExpandableNotificationRow) {
Mady Mellor34958fa2016-02-23 09:52:17 -08004780 return ((ExpandableNotificationRow) v).getTranslateViewAnimator(target, listener);
4781 } else {
4782 return super.getViewTranslationAnimator(v, target, listener);
Mady Mellor4b80b102016-01-22 08:03:58 -08004783 }
Mady Mellor4b80b102016-01-22 08:03:58 -08004784 }
4785
4786 @Override
4787 public void setTranslation(View v, float translate) {
Mady Mellor9c2c4962016-04-05 10:43:08 -07004788 ((ExpandableView) v).setTranslation(translate);
Mady Mellor4b80b102016-01-22 08:03:58 -08004789 }
4790
4791 @Override
4792 public float getTranslation(View v) {
Mady Mellor9c2c4962016-04-05 10:43:08 -07004793 return ((ExpandableView) v).getTranslation();
Mady Mellor4b80b102016-01-22 08:03:58 -08004794 }
4795
Mady Mellor95d743c2017-01-10 12:05:27 -08004796 @Override
4797 public void dismiss(View animView, float velocity) {
4798 dismissChild(animView, velocity,
4799 !swipedFastEnough(0, 0) /* useAccelerateInterpolator */);
4800 }
4801
4802 @Override
4803 public void snap(View animView, float targetLeft, float velocity) {
4804 snapChild(animView, targetLeft, velocity);
4805 }
4806
4807 @Override
4808 public boolean swipedFarEnough(float translation, float viewSize) {
4809 return swipedFarEnough();
4810 }
4811
4812 @Override
4813 public boolean swipedFastEnough(float translation, float velocity) {
4814 return swipedFastEnough();
4815 }
4816
4817 @Override
4818 public float getMinDismissVelocity() {
4819 return getEscapeVelocity();
4820 }
4821
4822 public void onMenuShown(View animView) {
4823 onDragCancelled(animView);
4824
4825 // If we're on the lockscreen we want to false this.
4826 if (isAntiFalsingNeeded()) {
4827 mHandler.removeCallbacks(mFalsingCheck);
4828 mHandler.postDelayed(mFalsingCheck, COVER_MENU_DELAY);
4829 }
4830 }
4831
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004832 public void closeControlsIfOutsideTouch(MotionEvent ev) {
Eliot Courtney47098cb2017-10-18 17:30:30 +09004833 NotificationGuts guts = mStatusBar.getGutsManager().getExposedGuts();
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004834 View view = null;
Mady Mellorc2dbe492017-03-30 13:22:03 -07004835 if (guts != null && !guts.getGutsContent().isLeavebehind()) {
4836 // Only close visible guts if they're not a leavebehind.
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004837 view = guts;
Mady Mellor95d743c2017-01-10 12:05:27 -08004838 } else if (mCurrMenuRow != null && mCurrMenuRow.isMenuVisible()
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004839 && mTranslatingParentView != null) {
Mady Mellor95d743c2017-01-10 12:05:27 -08004840 // Checking menu
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004841 view = mTranslatingParentView;
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004842 }
Mady Mellorc2dbe492017-03-30 13:22:03 -07004843 if (view != null && !isTouchInView(ev, view)) {
4844 // Touch was outside visible guts / menu notification, close what's visible
Eliot Courtney47098cb2017-10-18 17:30:30 +09004845 mStatusBar.getGutsManager().closeAndSaveGuts(false /* removeLeavebehind */,
4846 false /* force */, true /* removeControls */, -1 /* x */, -1 /* y */,
4847 false /* resetMenu */);
Mady Mellorc2dbe492017-03-30 13:22:03 -07004848 resetExposedMenuView(true /* animate */, true /* force */);
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004849 }
4850 }
4851
Mady Mellor95d743c2017-01-10 12:05:27 -08004852 public void resetExposedMenuView(boolean animate, boolean force) {
4853 if (mMenuExposedView == null
4854 || (!force && mMenuExposedView == mTranslatingParentView)) {
4855 // If no menu is showing or it's showing for this view we do nothing.
Mady Mellor4b80b102016-01-22 08:03:58 -08004856 return;
4857 }
Mady Mellor95d743c2017-01-10 12:05:27 -08004858 final View prevMenuExposedView = mMenuExposedView;
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004859 if (animate) {
Mady Mellor95d743c2017-01-10 12:05:27 -08004860 Animator anim = getViewTranslationAnimator(prevMenuExposedView,
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004861 0 /* leftTarget */, null /* updateListener */);
4862 if (anim != null) {
4863 anim.start();
4864 }
Mady Mellor95d743c2017-01-10 12:05:27 -08004865 } else if (mMenuExposedView instanceof ExpandableNotificationRow) {
Selim Cinekb2e0f332017-08-18 12:24:38 -07004866 ExpandableNotificationRow row = (ExpandableNotificationRow) mMenuExposedView;
4867 if (!row.isRemoved()) {
4868 row.resetTranslation();
4869 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004870 }
Mady Mellor95d743c2017-01-10 12:05:27 -08004871 mMenuExposedView = null;
Mady Mellor4b80b102016-01-22 08:03:58 -08004872 }
4873 }
4874
Mady Mellorc2dbe492017-03-30 13:22:03 -07004875 private boolean isTouchInView(MotionEvent ev, View view) {
4876 if (view == null) {
4877 return false;
4878 }
4879 final int height = (view instanceof ExpandableView)
4880 ? ((ExpandableView) view).getActualHeight()
4881 : view.getHeight();
4882 final int rx = (int) ev.getRawX();
4883 final int ry = (int) ev.getRawY();
4884 view.getLocationOnScreen(mTempInt2);
4885 final int x = mTempInt2[0];
4886 final int y = mTempInt2[1];
4887 Rect rect = new Rect(x, y, x + view.getWidth(), y + height);
4888 boolean ret = rect.contains(rx, ry);
4889 return ret;
4890 }
4891
Selim Cinek33223572016-02-19 19:32:22 -08004892 private void updateContinuousShadowDrawing() {
4893 boolean continuousShadowUpdate = mAnimationRunning
4894 || !mAmbientState.getDraggedViews().isEmpty();
4895 if (continuousShadowUpdate != mContinuousShadowUpdate) {
4896 if (continuousShadowUpdate) {
4897 getViewTreeObserver().addOnPreDrawListener(mShadowUpdater);
4898 } else {
4899 getViewTreeObserver().removeOnPreDrawListener(mShadowUpdater);
4900 }
Jorim Jaggi38b5ec92016-04-12 01:39:49 -07004901 mContinuousShadowUpdate = continuousShadowUpdate;
Selim Cinek33223572016-02-19 19:32:22 -08004902 }
4903 }
4904
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09004905 @Override
Mady Mellor95d743c2017-01-10 12:05:27 -08004906 public void resetExposedMenuView(boolean animate, boolean force) {
4907 mSwipeHelper.resetExposedMenuView(animate, force);
Mady Mellor7a9b2a62016-03-23 07:41:47 -07004908 }
4909
4910 public void closeControlsIfOutsideTouch(MotionEvent ev) {
4911 mSwipeHelper.closeControlsIfOutsideTouch(ev);
4912 }
4913
Jorim Jaggi0dd68812014-05-01 19:17:37 +02004914 static class AnimationEvent {
Selim Cinek572bbd42014-04-25 16:43:27 +02004915
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004916 static AnimationFilter[] FILTERS = new AnimationFilter[] {
4917
4918 // ANIMATION_TYPE_ADD
4919 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004920 .animateShadowAlpha()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004921 .animateHeight()
Selim Cinek708a6c12014-05-28 14:16:02 +02004922 .animateTopInset()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004923 .animateY()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004924 .animateZ()
4925 .hasDelays(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004926
4927 // ANIMATION_TYPE_REMOVE
4928 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004929 .animateShadowAlpha()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004930 .animateHeight()
Selim Cinek708a6c12014-05-28 14:16:02 +02004931 .animateTopInset()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004932 .animateY()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004933 .animateZ()
4934 .hasDelays(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004935
4936 // ANIMATION_TYPE_REMOVE_SWIPED_OUT
4937 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004938 .animateShadowAlpha()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004939 .animateHeight()
Selim Cinek708a6c12014-05-28 14:16:02 +02004940 .animateTopInset()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004941 .animateY()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004942 .animateZ()
4943 .hasDelays(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004944
4945 // ANIMATION_TYPE_TOP_PADDING_CHANGED
4946 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004947 .animateShadowAlpha()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004948 .animateHeight()
Selim Cinek708a6c12014-05-28 14:16:02 +02004949 .animateTopInset()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004950 .animateY()
4951 .animateDimmed()
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004952 .animateZ(),
4953
4954 // ANIMATION_TYPE_START_DRAG
4955 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004956 .animateShadowAlpha(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004957
4958 // ANIMATION_TYPE_SNAP_BACK
4959 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004960 .animateShadowAlpha()
Jorim Jaggidbc3dce2014-08-01 01:16:36 +02004961 .animateHeight(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004962
4963 // ANIMATION_TYPE_ACTIVATED_CHILD
4964 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004965 .animateZ(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02004966
4967 // ANIMATION_TYPE_DIMMED
4968 new AnimationFilter()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004969 .animateDimmed(),
4970
4971 // ANIMATION_TYPE_CHANGE_POSITION
4972 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004973 .animateAlpha() // maybe the children change positions
4974 .animateShadowAlpha()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004975 .animateHeight()
Selim Cinek708a6c12014-05-28 14:16:02 +02004976 .animateTopInset()
Selim Cinek8efa6dd2014-05-19 16:27:37 +02004977 .animateY()
John Spurlockbf370992014-06-17 13:58:31 -04004978 .animateZ(),
4979
4980 // ANIMATION_TYPE_DARK
Adrian Roos28f90c72017-05-08 17:24:26 -07004981 null, // Unused
Jorim Jaggi60d07c52014-07-31 15:38:21 +02004982
4983 // ANIMATION_TYPE_GO_TO_FULL_SHADE
4984 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004985 .animateShadowAlpha()
Jorim Jaggi60d07c52014-07-31 15:38:21 +02004986 .animateHeight()
4987 .animateTopInset()
4988 .animateY()
4989 .animateDimmed()
Jorim Jaggiae441282014-08-01 02:45:18 +02004990 .animateZ()
4991 .hasDelays(),
4992
4993 // ANIMATION_TYPE_HIDE_SENSITIVE
4994 new AnimationFilter()
4995 .animateHideSensitive(),
Selim Cineka5e211b2014-08-11 17:35:48 +02004996
4997 // ANIMATION_TYPE_VIEW_RESIZE
4998 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08004999 .animateShadowAlpha()
Selim Cineka5e211b2014-08-11 17:35:48 +02005000 .animateHeight()
5001 .animateTopInset()
5002 .animateY()
5003 .animateZ(),
Selim Cinekd9acca52014-09-01 22:33:25 +02005004
Selim Cinekb5605e52015-02-20 18:21:41 +01005005 // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED
5006 new AnimationFilter()
5007 .animateAlpha()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005008 .animateShadowAlpha()
Selim Cinekb5605e52015-02-20 18:21:41 +01005009 .animateHeight()
5010 .animateTopInset()
5011 .animateY()
5012 .animateZ(),
5013
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005014 // ANIMATION_TYPE_HEADS_UP_APPEAR
5015 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005016 .animateShadowAlpha()
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005017 .animateHeight()
5018 .animateTopInset()
5019 .animateY()
5020 .animateZ(),
5021
5022 // ANIMATION_TYPE_HEADS_UP_DISAPPEAR
5023 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005024 .animateShadowAlpha()
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005025 .animateHeight()
5026 .animateTopInset()
5027 .animateY()
Selim Cinek332c23f2018-03-16 17:37:50 -07005028 .animateZ()
5029 .hasDelays(),
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005030
Jorim Jaggi5eb67c22015-08-19 19:50:49 -07005031 // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK
5032 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005033 .animateShadowAlpha()
Jorim Jaggi5eb67c22015-08-19 19:50:49 -07005034 .animateHeight()
5035 .animateTopInset()
5036 .animateY()
5037 .animateZ()
5038 .hasDelays(),
5039
Selim Cineka59ecc32015-04-07 10:51:49 -07005040 // ANIMATION_TYPE_HEADS_UP_OTHER
5041 new AnimationFilter()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005042 .animateShadowAlpha()
Selim Cineka59ecc32015-04-07 10:51:49 -07005043 .animateHeight()
5044 .animateTopInset()
5045 .animateY()
5046 .animateZ(),
5047
Selim Cinekd9acca52014-09-01 22:33:25 +02005048 // ANIMATION_TYPE_EVERYTHING
5049 new AnimationFilter()
5050 .animateAlpha()
Selim Cinek277a8aa2016-01-22 12:12:37 -08005051 .animateShadowAlpha()
Selim Cinekd9acca52014-09-01 22:33:25 +02005052 .animateDark()
Selim Cinekd9acca52014-09-01 22:33:25 +02005053 .animateDimmed()
5054 .animateHideSensitive()
5055 .animateHeight()
5056 .animateTopInset()
5057 .animateY()
5058 .animateZ(),
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005059
5060 // ANIMATION_TYPE_PULSE_APPEAR
5061 new AnimationFilter()
5062 .animateAlpha()
Lucas Dupin2a6bdfd2018-06-12 17:45:21 -07005063 .hasDelays()
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005064 .animateY(),
5065
5066 // ANIMATION_TYPE_PULSE_DISAPPEAR
5067 new AnimationFilter()
5068 .animateAlpha()
Lucas Dupin2a6bdfd2018-06-12 17:45:21 -07005069 .hasDelays()
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005070 .animateY(),
Jorim Jaggid552d9d2014-05-07 19:41:13 +02005071 };
5072
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005073 static int[] LENGTHS = new int[] {
5074
5075 // ANIMATION_TYPE_ADD
Selim Cinek8efa6dd2014-05-19 16:27:37 +02005076 StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR,
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005077
5078 // ANIMATION_TYPE_REMOVE
Selim Cinek8efa6dd2014-05-19 16:27:37 +02005079 StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR,
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005080
5081 // ANIMATION_TYPE_REMOVE_SWIPED_OUT
5082 StackStateAnimator.ANIMATION_DURATION_STANDARD,
5083
5084 // ANIMATION_TYPE_TOP_PADDING_CHANGED
5085 StackStateAnimator.ANIMATION_DURATION_STANDARD,
5086
5087 // ANIMATION_TYPE_START_DRAG
5088 StackStateAnimator.ANIMATION_DURATION_STANDARD,
5089
5090 // ANIMATION_TYPE_SNAP_BACK
5091 StackStateAnimator.ANIMATION_DURATION_STANDARD,
5092
5093 // ANIMATION_TYPE_ACTIVATED_CHILD
5094 StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED,
5095
5096 // ANIMATION_TYPE_DIMMED
5097 StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED,
Selim Cinek8efa6dd2014-05-19 16:27:37 +02005098
5099 // ANIMATION_TYPE_CHANGE_POSITION
5100 StackStateAnimator.ANIMATION_DURATION_STANDARD,
John Spurlockbf370992014-06-17 13:58:31 -04005101
5102 // ANIMATION_TYPE_DARK
Adrian Roos28f90c72017-05-08 17:24:26 -07005103 StackStateAnimator.ANIMATION_DURATION_WAKEUP,
Jorim Jaggi60d07c52014-07-31 15:38:21 +02005104
5105 // ANIMATION_TYPE_GO_TO_FULL_SHADE
5106 StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE,
Jorim Jaggiae441282014-08-01 02:45:18 +02005107
5108 // ANIMATION_TYPE_HIDE_SENSITIVE
5109 StackStateAnimator.ANIMATION_DURATION_STANDARD,
Selim Cineka5e211b2014-08-11 17:35:48 +02005110
5111 // ANIMATION_TYPE_VIEW_RESIZE
5112 StackStateAnimator.ANIMATION_DURATION_STANDARD,
Selim Cinekd9acca52014-09-01 22:33:25 +02005113
Selim Cinekb5605e52015-02-20 18:21:41 +01005114 // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED
Selim Cinek99695592016-01-12 17:51:35 -08005115 StackStateAnimator.ANIMATION_DURATION_STANDARD,
Selim Cinekb5605e52015-02-20 18:21:41 +01005116
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005117 // ANIMATION_TYPE_HEADS_UP_APPEAR
5118 StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR,
5119
5120 // ANIMATION_TYPE_HEADS_UP_DISAPPEAR
5121 StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR,
5122
Jorim Jaggi5eb67c22015-08-19 19:50:49 -07005123 // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK
5124 StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR,
5125
Selim Cineka59ecc32015-04-07 10:51:49 -07005126 // ANIMATION_TYPE_HEADS_UP_OTHER
5127 StackStateAnimator.ANIMATION_DURATION_STANDARD,
5128
Selim Cinekd9acca52014-09-01 22:33:25 +02005129 // ANIMATION_TYPE_EVERYTHING
5130 StackStateAnimator.ANIMATION_DURATION_STANDARD,
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005131
5132 // ANIMATION_TYPE_PULSE_APPEAR
Lucas Dupin2a6bdfd2018-06-12 17:45:21 -07005133 StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR,
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005134
5135 // ANIMATION_TYPE_PULSE_DISAPPEAR
Lucas Dupin2a6bdfd2018-06-12 17:45:21 -07005136 StackStateAnimator.ANIMATION_DURATION_PULSE_APPEAR / 2,
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005137 };
5138
Selim Cinek8efa6dd2014-05-19 16:27:37 +02005139 static final int ANIMATION_TYPE_ADD = 0;
5140 static final int ANIMATION_TYPE_REMOVE = 1;
5141 static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2;
5142 static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3;
5143 static final int ANIMATION_TYPE_START_DRAG = 4;
5144 static final int ANIMATION_TYPE_SNAP_BACK = 5;
5145 static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6;
5146 static final int ANIMATION_TYPE_DIMMED = 7;
5147 static final int ANIMATION_TYPE_CHANGE_POSITION = 8;
John Spurlockbf370992014-06-17 13:58:31 -04005148 static final int ANIMATION_TYPE_DARK = 9;
Jorim Jaggi60d07c52014-07-31 15:38:21 +02005149 static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10;
Jorim Jaggiae441282014-08-01 02:45:18 +02005150 static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11;
Selim Cineka5e211b2014-08-11 17:35:48 +02005151 static final int ANIMATION_TYPE_VIEW_RESIZE = 12;
Selim Cinekb5605e52015-02-20 18:21:41 +01005152 static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 13;
Selim Cinekb8f09cf2015-03-16 17:09:28 -07005153 static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 14;
5154 static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 15;
Jorim Jaggi5eb67c22015-08-19 19:50:49 -07005155 static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 16;
5156 static final int ANIMATION_TYPE_HEADS_UP_OTHER = 17;
5157 static final int ANIMATION_TYPE_EVERYTHING = 18;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -07005158 static final int ANIMATION_TYPE_PULSE_APPEAR = 19;
5159 static final int ANIMATION_TYPE_PULSE_DISAPPEAR = 20;
Jorim Jaggi0dd68812014-05-01 19:17:37 +02005160
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01005161 static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1;
5162 static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2;
5163
Selim Cinek572bbd42014-04-25 16:43:27 +02005164 final long eventStartTime;
5165 final View changingView;
5166 final int animationType;
Jorim Jaggid552d9d2014-05-07 19:41:13 +02005167 final AnimationFilter filter;
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005168 final long length;
Selim Cinek8efa6dd2014-05-19 16:27:37 +02005169 View viewAfterChangingView;
Jorim Jaggi2a5e4522014-11-24 21:45:20 +01005170 int darkAnimationOriginIndex;
Selim Cineka59ecc32015-04-07 10:51:49 -07005171 boolean headsUpFromBottom;
Selim Cinek572bbd42014-04-25 16:43:27 +02005172
Jorim Jaggi0dd68812014-05-01 19:17:37 +02005173 AnimationEvent(View view, int type) {
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02005174 this(view, type, LENGTHS[type]);
5175 }
5176
Adrian Roos28f90c72017-05-08 17:24:26 -07005177 AnimationEvent(View view, int type, AnimationFilter filter) {
5178 this(view, type, LENGTHS[type], filter);
5179 }
5180
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02005181 AnimationEvent(View view, int type, long length) {
Adrian Roos28f90c72017-05-08 17:24:26 -07005182 this(view, type, length, FILTERS[type]);
5183 }
5184
5185 AnimationEvent(View view, int type, long length, AnimationFilter filter) {
Selim Cinek572bbd42014-04-25 16:43:27 +02005186 eventStartTime = AnimationUtils.currentAnimationTimeMillis();
5187 changingView = view;
5188 animationType = type;
Jorim Jaggiff9c9c42014-08-01 05:36:22 +02005189 this.length = length;
Adrian Roos28f90c72017-05-08 17:24:26 -07005190 this.filter = filter;
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005191 }
5192
5193 /**
5194 * Combines the length of several animation events into a single value.
5195 *
5196 * @param events The events of the lengths to combine.
Jorim Jaggi60d07c52014-07-31 15:38:21 +02005197 * @return The combined length. Depending on the event types, this might be the maximum of
5198 * all events or the length of a specific event.
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005199 */
5200 static long combineLength(ArrayList<AnimationEvent> events) {
5201 long length = 0;
5202 int size = events.size();
5203 for (int i = 0; i < size; i++) {
Jorim Jaggi60d07c52014-07-31 15:38:21 +02005204 AnimationEvent event = events.get(i);
5205 length = Math.max(length, event.length);
5206 if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) {
5207 return event.length;
5208 }
Jorim Jaggi5aa045c2014-05-07 21:42:40 +02005209 }
5210 return length;
Selim Cinek572bbd42014-04-25 16:43:27 +02005211 }
5212 }
Selim Cinek67b22602014-03-10 15:40:16 +01005213}