Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.stack; |
| 18 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.Configuration; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 22 | import android.graphics.Canvas; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 23 | import android.graphics.Paint; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 24 | import android.graphics.PointF; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 25 | import android.util.AttributeSet; |
| 26 | import android.util.Log; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 27 | import android.util.Pair; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 28 | import android.view.MotionEvent; |
| 29 | import android.view.VelocityTracker; |
| 30 | import android.view.View; |
| 31 | import android.view.ViewConfiguration; |
| 32 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 33 | import android.view.ViewTreeObserver; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 34 | import android.view.animation.AnimationUtils; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 35 | import android.widget.OverScroller; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 36 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 37 | import com.android.systemui.ExpandHelper; |
| 38 | import com.android.systemui.R; |
| 39 | import com.android.systemui.SwipeHelper; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 40 | import com.android.systemui.classifier.FalsingManager; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 41 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.DismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 43 | import com.android.systemui.statusbar.EmptyShadeView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 44 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 45 | import com.android.systemui.statusbar.ExpandableView; |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 46 | import com.android.systemui.statusbar.NotificationOverflowContainer; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 47 | import com.android.systemui.statusbar.StackScrollerDecorView; |
Selim Cinek | cb2b673 | 2014-09-05 16:17:22 +0200 | [diff] [blame] | 48 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 49 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 50 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.phone.ScrimController; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 53 | import com.android.systemui.statusbar.policy.ScrollAdapter; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 54 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 55 | import java.util.ArrayList; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 56 | import java.util.HashSet; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 57 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 58 | /** |
| 59 | * A layout which handles a dynamic amount of notifications and presents them in a scrollable stack. |
| 60 | */ |
| 61 | public class NotificationStackScrollLayout extends ViewGroup |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 62 | implements SwipeHelper.Callback, ExpandHelper.Callback, ScrollAdapter, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 63 | ExpandableView.OnHeightChangedListener, NotificationGroupManager.OnGroupChangeListener { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 64 | |
| 65 | private static final String TAG = "NotificationStackScrollLayout"; |
| 66 | private static final boolean DEBUG = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 67 | private static final float RUBBER_BAND_FACTOR_NORMAL = 0.35f; |
| 68 | private static final float RUBBER_BAND_FACTOR_AFTER_EXPAND = 0.15f; |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 69 | private static final float RUBBER_BAND_FACTOR_ON_PANEL_EXPAND = 0.21f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Sentinel value for no current active pointer. Used by {@link #mActivePointerId}. |
| 73 | */ |
| 74 | private static final int INVALID_POINTER = -1; |
| 75 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 76 | private ExpandHelper mExpandHelper; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 77 | private SwipeHelper mSwipeHelper; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 78 | private boolean mSwipingInProgress; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 79 | private int mCurrentStackHeight = Integer.MAX_VALUE; |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * mCurrentStackHeight is the actual stack height, mLastSetStackHeight is the stack height set |
| 83 | * externally from {@link #setStackHeight} |
| 84 | */ |
| 85 | private float mLastSetStackHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 86 | private int mOwnScrollY; |
| 87 | private int mMaxLayoutHeight; |
| 88 | |
| 89 | private VelocityTracker mVelocityTracker; |
| 90 | private OverScroller mScroller; |
| 91 | private int mTouchSlop; |
| 92 | private int mMinimumVelocity; |
| 93 | private int mMaximumVelocity; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 94 | private int mOverflingDistance; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 95 | private float mMaxOverScroll; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 96 | private boolean mIsBeingDragged; |
| 97 | private int mLastMotionY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 98 | private int mDownX; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 99 | private int mActivePointerId; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 100 | private boolean mTouchIsClick; |
| 101 | private float mInitialTouchX; |
| 102 | private float mInitialTouchY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 103 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 104 | private Paint mDebugPaint; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 105 | private int mContentHeight; |
| 106 | private int mCollapsedSize; |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 107 | private int mBottomStackSlowDownHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 108 | private int mBottomStackPeekSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 109 | private int mPaddingBetweenElements; |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 110 | private int mPaddingBetweenElementsNormal; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 111 | private int mTopPadding; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 112 | private int mCollapseSecondCardPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * The algorithm which calculates the properties for our children |
| 116 | */ |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 117 | private final StackScrollAlgorithm mStackScrollAlgorithm; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * The current State this Layout is in |
| 121 | */ |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 122 | private StackScrollState mCurrentStackScrollState = new StackScrollState(this); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 123 | private AmbientState mAmbientState = new AmbientState(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 124 | private NotificationGroupManager mGroupManager; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 125 | private ArrayList<View> mChildrenToAddAnimated = new ArrayList<>(); |
| 126 | private ArrayList<View> mAddedHeadsUpChildren = new ArrayList<>(); |
| 127 | private ArrayList<View> mChildrenToRemoveAnimated = new ArrayList<>(); |
| 128 | private ArrayList<View> mSnappedBackChildren = new ArrayList<>(); |
| 129 | private ArrayList<View> mDragAnimPendingChildren = new ArrayList<>(); |
| 130 | private ArrayList<View> mChildrenChangingPositions = new ArrayList<>(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 131 | private HashSet<View> mFromMoreCardAdditions = new HashSet<>(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 132 | private ArrayList<AnimationEvent> mAnimationEvents = new ArrayList<>(); |
| 133 | private ArrayList<View> mSwipedOutViews = new ArrayList<>(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 134 | private final StackStateAnimator mStateAnimator = new StackStateAnimator(this); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 135 | private boolean mAnimationsEnabled; |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 136 | private boolean mChangePositionInProgress; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 137 | private boolean mChildTransferInProgress; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 138 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 139 | /** |
| 140 | * The raw amount of the overScroll on the top, which is not rubber-banded. |
| 141 | */ |
| 142 | private float mOverScrolledTopPixels; |
| 143 | |
| 144 | /** |
| 145 | * The raw amount of the overScroll on the bottom, which is not rubber-banded. |
| 146 | */ |
| 147 | private float mOverScrolledBottomPixels; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 148 | private OnChildLocationsChangedListener mListener; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 149 | private OnOverscrollTopChangedListener mOverscrollTopChangedListener; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 150 | private ExpandableView.OnHeightChangedListener mOnHeightChangedListener; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 151 | private OnEmptySpaceClickListener mOnEmptySpaceClickListener; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 152 | private boolean mNeedsAnimation; |
| 153 | private boolean mTopPaddingNeedsAnimation; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 154 | private boolean mDimmedNeedsAnimation; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 155 | private boolean mHideSensitiveNeedsAnimation; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 156 | private boolean mDarkNeedsAnimation; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 157 | private int mDarkAnimationOriginIndex; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 158 | private boolean mActivateNeedsAnimation; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 159 | private boolean mGoToFullShadeNeedsAnimation; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 160 | private boolean mIsExpanded = true; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 161 | private boolean mChildrenUpdateRequested; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 162 | private boolean mIsExpansionChanging; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 163 | private boolean mPanelTracking; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 164 | private boolean mExpandingNotification; |
| 165 | private boolean mExpandedInThisMotion; |
| 166 | private boolean mScrollingEnabled; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 167 | private DismissView mDismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 168 | private EmptyShadeView mEmptyShadeView; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 169 | private boolean mDismissAllInProgress; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * Was the scroller scrolled to the top when the down motion was observed? |
| 173 | */ |
| 174 | private boolean mScrolledToTopOnFirstDown; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 175 | /** |
| 176 | * The minimal amount of over scroll which is needed in order to switch to the quick settings |
| 177 | * when over scrolling on a expanded card. |
| 178 | */ |
| 179 | private float mMinTopOverScrollToEscape; |
| 180 | private int mIntrinsicPadding; |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 181 | private float mStackTranslation; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 182 | private float mTopPaddingOverflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 183 | private boolean mDontReportNextOverScroll; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 184 | private boolean mRequestViewResizeAnimationOnLayout; |
| 185 | private boolean mNeedViewResizeAnimation; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 186 | private View mExpandedGroupView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 187 | private boolean mEverythingNeedsAnimation; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 188 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 189 | /** |
| 190 | * The maximum scrollPosition which we are allowed to reach when a notification was expanded. |
| 191 | * This is needed to avoid scrolling too far after the notification was collapsed in the same |
| 192 | * motion. |
| 193 | */ |
| 194 | private int mMaxScrollAfterExpand; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 195 | private SwipeHelper.LongPressListener mLongPressListener; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Should in this touch motion only be scrolling allowed? It's true when the scroller was |
| 199 | * animating. |
| 200 | */ |
| 201 | private boolean mOnlyScrollingInThisMotion; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 202 | private ViewGroup mScrollView; |
| 203 | private boolean mInterceptDelegateEnabled; |
| 204 | private boolean mDelegateToScrollView; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 205 | private boolean mDisallowScrollingInThisMotion; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 206 | private long mGoToFullShadeDelay; |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 207 | private ViewTreeObserver.OnPreDrawListener mChildrenUpdater |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 208 | = new ViewTreeObserver.OnPreDrawListener() { |
| 209 | @Override |
| 210 | public boolean onPreDraw() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 211 | updateChildren(); |
| 212 | mChildrenUpdateRequested = false; |
| 213 | getViewTreeObserver().removeOnPreDrawListener(this); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 214 | return true; |
| 215 | } |
| 216 | }; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 217 | private PhoneStatusBar mPhoneStatusBar; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 218 | private int[] mTempInt2 = new int[2]; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 219 | private boolean mGenerateChildOrderChangedEvent; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 220 | private HashSet<Runnable> mAnimationFinishedRunnables = new HashSet<>(); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 221 | private HashSet<View> mClearOverlayViewsWhenFinished = new HashSet<>(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 222 | private HashSet<Pair<ExpandableNotificationRow, Boolean>> mHeadsUpChangeAnimations |
| 223 | = new HashSet<>(); |
| 224 | private HeadsUpManager mHeadsUpManager; |
| 225 | private boolean mTrackingHeadsUp; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 226 | private ScrimController mScrimController; |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 227 | private boolean mForceNoOverlappingRendering; |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 228 | private NotificationOverflowContainer mOverflowContainer; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 229 | private final ArrayList<Pair<ExpandableNotificationRow, Boolean>> mTmpList = new ArrayList<>(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 230 | private FalsingManager mFalsingManager; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 231 | |
| 232 | public NotificationStackScrollLayout(Context context) { |
| 233 | this(context, null); |
| 234 | } |
| 235 | |
| 236 | public NotificationStackScrollLayout(Context context, AttributeSet attrs) { |
| 237 | this(context, attrs, 0); |
| 238 | } |
| 239 | |
| 240 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 241 | this(context, attrs, defStyleAttr, 0); |
| 242 | } |
| 243 | |
| 244 | public NotificationStackScrollLayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 245 | int defStyleRes) { |
| 246 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | 1cf41c1 | 2014-08-12 20:06:19 +0200 | [diff] [blame] | 247 | int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); |
| 248 | int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height); |
| 249 | mExpandHelper = new ExpandHelper(getContext(), this, |
| 250 | minHeight, maxHeight); |
| 251 | mExpandHelper.setEventSource(this); |
| 252 | mExpandHelper.setScrollAdapter(this); |
| 253 | |
| 254 | mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, getContext()); |
| 255 | mSwipeHelper.setLongPressListener(mLongPressListener); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 256 | mStackScrollAlgorithm = new StackScrollAlgorithm(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 257 | initView(context); |
| 258 | if (DEBUG) { |
| 259 | setWillNotDraw(false); |
| 260 | mDebugPaint = new Paint(); |
| 261 | mDebugPaint.setColor(0xffff0000); |
| 262 | mDebugPaint.setStrokeWidth(2); |
| 263 | mDebugPaint.setStyle(Paint.Style.STROKE); |
| 264 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 265 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | @Override |
| 269 | protected void onDraw(Canvas canvas) { |
| 270 | if (DEBUG) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 271 | int y = mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 272 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 273 | y = (int) (getLayoutHeight() - mBottomStackPeekSize |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 274 | - mBottomStackSlowDownHeight); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 275 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 276 | y = (int) (getLayoutHeight() - mBottomStackPeekSize); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 277 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
| 278 | y = (int) getLayoutHeight(); |
| 279 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 280 | y = getHeight() - getEmptyBottomMargin(); |
| 281 | canvas.drawLine(0, y, getWidth(), y, mDebugPaint); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | private void initView(Context context) { |
| 286 | mScroller = new OverScroller(getContext()); |
| 287 | setFocusable(true); |
| 288 | setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 289 | setClipChildren(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 290 | final ViewConfiguration configuration = ViewConfiguration.get(context); |
| 291 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 292 | mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); |
| 293 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 294 | mOverflingDistance = configuration.getScaledOverflingDistance(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 295 | mCollapsedSize = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 296 | .getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 297 | mBottomStackPeekSize = context.getResources() |
| 298 | .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 299 | mStackScrollAlgorithm.initView(context); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 300 | mPaddingBetweenElementsNormal = context.getResources() |
| 301 | .getDimensionPixelSize(R.dimen.notification_padding); |
Selim Cinek | 587cbf3 | 2016-01-19 11:36:18 -0800 | [diff] [blame] | 302 | mPaddingBetweenElements = mPaddingBetweenElementsNormal; |
| 303 | mBottomStackSlowDownHeight = mStackScrollAlgorithm.getBottomStackSlowDownLength(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 304 | mMinTopOverScrollToEscape = getResources().getDimensionPixelSize( |
| 305 | R.dimen.min_top_overscroll_to_qs); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 306 | mCollapseSecondCardPadding = getResources().getDimensionPixelSize( |
| 307 | R.dimen.notification_collapse_second_card_padding); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 310 | private void notifyHeightChangeListener(ExpandableView view) { |
| 311 | if (mOnHeightChangedListener != null) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 312 | mOnHeightChangedListener.onHeightChanged(view, false /* needsAnimation */); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 313 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Override |
| 317 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 318 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | 924c612 | 2016-01-15 18:24:05 -0800 | [diff] [blame] | 319 | measureChildren(widthMeasureSpec, heightMeasureSpec); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Override |
| 323 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 324 | |
| 325 | // we layout all our children centered on the top |
| 326 | float centerX = getWidth() / 2.0f; |
| 327 | for (int i = 0; i < getChildCount(); i++) { |
| 328 | View child = getChildAt(i); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 329 | if (child.getVisibility() == GONE) { |
| 330 | continue; |
| 331 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 332 | float width = child.getMeasuredWidth(); |
| 333 | float height = child.getMeasuredHeight(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 334 | child.layout((int) (centerX - width / 2.0f), |
| 335 | 0, |
| 336 | (int) (centerX + width / 2.0f), |
| 337 | (int) height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 338 | } |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 339 | setMaxLayoutHeight(getHeight()); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 340 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 341 | clampScrollPosition(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 342 | if (mRequestViewResizeAnimationOnLayout) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 343 | requestAnimationOnViewResize(null); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 344 | mRequestViewResizeAnimationOnLayout = false; |
| 345 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 346 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 349 | private void requestAnimationOnViewResize(ExpandableNotificationRow row) { |
| 350 | if (mAnimationsEnabled && (mIsExpanded || row != null && row.isPinned())) { |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 351 | mNeedViewResizeAnimation = true; |
| 352 | mNeedsAnimation = true; |
| 353 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 356 | public void updateSpeedBumpIndex(int newIndex) { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 357 | mAmbientState.setSpeedBumpIndex(newIndex); |
| 358 | } |
| 359 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 360 | public void setChildLocationsChangedListener(OnChildLocationsChangedListener listener) { |
| 361 | mListener = listener; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Returns the location the given child is currently rendered at. |
| 366 | * |
| 367 | * @param child the child to get the location for |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 368 | * @return one of {@link StackViewState}'s <code>LOCATION_*</code> constants |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 369 | */ |
| 370 | public int getChildLocation(View child) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 371 | StackViewState childViewState = mCurrentStackScrollState.getViewStateForView(child); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 372 | if (childViewState == null) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 373 | return StackViewState.LOCATION_UNKNOWN; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 374 | } |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 375 | if (childViewState.gone) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 376 | return StackViewState.LOCATION_GONE; |
Christoph Studer | 12cf9e5 | 2014-10-29 17:35:30 +0100 | [diff] [blame] | 377 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 378 | return childViewState.location; |
| 379 | } |
| 380 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 381 | private void setMaxLayoutHeight(int maxLayoutHeight) { |
| 382 | mMaxLayoutHeight = maxLayoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 383 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 386 | private void updateAlgorithmHeightAndPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 387 | mAmbientState.setLayoutHeight(getLayoutHeight()); |
| 388 | mAmbientState.setTopPadding(mTopPadding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 392 | * @return whether the height of the layout needs to be adapted, in order to ensure that the |
| 393 | * last child is not in the bottom stack. |
| 394 | */ |
| 395 | private boolean needsHeightAdaption() { |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 396 | return getNotGoneChildCount() > 1; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 397 | } |
| 398 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 399 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 400 | * Updates the children views according to the stack scroll algorithm. Call this whenever |
| 401 | * modifications to {@link #mOwnScrollY} are performed to reflect it in the view layout. |
| 402 | */ |
| 403 | private void updateChildren() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 404 | mAmbientState.setScrollY(mOwnScrollY); |
| 405 | mStackScrollAlgorithm.getStackScrollState(mAmbientState, mCurrentStackScrollState); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 406 | if (!isCurrentlyAnimating() && !mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 407 | applyCurrentState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 408 | } else { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 409 | startAnimationToState(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 413 | private void requestChildrenUpdate() { |
Selim Cinek | 1f553cf | 2014-05-02 12:01:36 +0200 | [diff] [blame] | 414 | if (!mChildrenUpdateRequested) { |
| 415 | getViewTreeObserver().addOnPreDrawListener(mChildrenUpdater); |
| 416 | mChildrenUpdateRequested = true; |
| 417 | invalidate(); |
| 418 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 421 | private boolean isCurrentlyAnimating() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 422 | return mStateAnimator.isRunning(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 425 | private void clampScrollPosition() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 426 | int scrollRange = getScrollRange(); |
| 427 | if (scrollRange < mOwnScrollY) { |
| 428 | mOwnScrollY = scrollRange; |
| 429 | } |
| 430 | } |
| 431 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 432 | public int getTopPadding() { |
| 433 | return mTopPadding; |
| 434 | } |
| 435 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 436 | private void setTopPadding(int topPadding, boolean animate) { |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 437 | if (mTopPadding != topPadding) { |
| 438 | mTopPadding = topPadding; |
| 439 | updateAlgorithmHeightAndPadding(); |
| 440 | updateContentHeight(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 441 | if (animate && mAnimationsEnabled && mIsExpanded) { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 442 | mTopPaddingNeedsAnimation = true; |
| 443 | mNeedsAnimation = true; |
| 444 | } |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 445 | requestChildrenUpdate(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 446 | notifyHeightChangeListener(null); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Update the height of the stack to a new height. |
| 452 | * |
| 453 | * @param height the new height of the stack |
| 454 | */ |
| 455 | public void setStackHeight(float height) { |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 456 | mLastSetStackHeight = height; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 457 | setIsExpanded(height > 0.0f); |
| 458 | int newStackHeight = (int) height; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 459 | int minStackHeight = getMinStackHeight(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 460 | int stackHeight; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 461 | float paddingOffset; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 462 | boolean trackingHeadsUp = mTrackingHeadsUp || mHeadsUpManager.hasPinnedHeadsUp(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 463 | int normalUnfoldPositionStart = trackingHeadsUp |
| 464 | ? mHeadsUpManager.getTopHeadsUpPinnedHeight() |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 465 | : minStackHeight; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 466 | if (newStackHeight - mTopPadding - mTopPaddingOverflow >= normalUnfoldPositionStart |
Jorim Jaggi | 58bef33 | 2014-11-21 18:10:32 +0100 | [diff] [blame] | 467 | || getNotGoneChildCount() == 0) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 468 | paddingOffset = mTopPaddingOverflow; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 469 | stackHeight = newStackHeight; |
| 470 | } else { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 471 | int translationY; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 472 | if (!trackingHeadsUp) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 473 | // We did not reach the position yet where we actually start growing, |
| 474 | // so we translate the stack upwards. |
| 475 | translationY = (newStackHeight - minStackHeight); |
| 476 | // A slight parallax effect is introduced in order for the stack to catch up with |
| 477 | // the top card. |
| 478 | float partiallyThere = (newStackHeight - mTopPadding - mTopPaddingOverflow) |
| 479 | / minStackHeight; |
| 480 | partiallyThere = Math.max(0, partiallyThere); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 481 | translationY += (1 - partiallyThere) * (mBottomStackPeekSize + |
| 482 | mCollapseSecondCardPadding); |
| 483 | } else { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 484 | translationY = (int) (height - normalUnfoldPositionStart); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 485 | } |
| 486 | paddingOffset = translationY - mTopPadding; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 487 | stackHeight = (int) (height - (translationY - mTopPadding)); |
| 488 | } |
| 489 | if (stackHeight != mCurrentStackHeight) { |
| 490 | mCurrentStackHeight = stackHeight; |
| 491 | updateAlgorithmHeightAndPadding(); |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 492 | requestChildrenUpdate(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 493 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 494 | setStackTranslation(paddingOffset); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 497 | public float getStackTranslation() { |
| 498 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 501 | private void setStackTranslation(float stackTranslation) { |
| 502 | if (stackTranslation != mStackTranslation) { |
| 503 | mStackTranslation = stackTranslation; |
| 504 | mAmbientState.setStackTranslation(stackTranslation); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 505 | requestChildrenUpdate(); |
| 506 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 510 | * Get the current height of the view. This is at most the msize of the view given by a the |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 511 | * layout but it can also be made smaller by setting {@link #mCurrentStackHeight} |
| 512 | * |
| 513 | * @return either the layout height or the externally defined height, whichever is smaller |
| 514 | */ |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 515 | private int getLayoutHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 516 | return Math.min(mMaxLayoutHeight, mCurrentStackHeight); |
| 517 | } |
| 518 | |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 519 | public int getFirstItemMinHeight() { |
| 520 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 521 | return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | public int getBottomStackPeekSize() { |
| 525 | return mBottomStackPeekSize; |
| 526 | } |
| 527 | |
Jorim Jaggi | 5ad92c5 | 2014-07-28 21:07:32 +0200 | [diff] [blame] | 528 | public int getCollapseSecondCardPadding() { |
| 529 | return mCollapseSecondCardPadding; |
| 530 | } |
| 531 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 532 | public void setLongPressListener(SwipeHelper.LongPressListener listener) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 533 | mSwipeHelper.setLongPressListener(listener); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 534 | mLongPressListener = listener; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 537 | public void setScrollView(ViewGroup scrollView) { |
| 538 | mScrollView = scrollView; |
| 539 | } |
| 540 | |
| 541 | public void setInterceptDelegateEnabled(boolean interceptDelegateEnabled) { |
| 542 | mInterceptDelegateEnabled = interceptDelegateEnabled; |
| 543 | } |
| 544 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 545 | public void onChildDismissed(View v) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 546 | if (mDismissAllInProgress) { |
| 547 | return; |
| 548 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 549 | setSwipingInProgress(false); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 550 | if (mDragAnimPendingChildren.contains(v)) { |
| 551 | // We start the swipe and finish it in the same frame, we don't want any animation |
| 552 | // for the drag |
| 553 | mDragAnimPendingChildren.remove(v); |
| 554 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 555 | mSwipedOutViews.add(v); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 556 | mAmbientState.onDragFinished(v); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 557 | if (v instanceof ExpandableNotificationRow) { |
| 558 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 559 | if (row.isHeadsUp()) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 560 | mHeadsUpManager.addSwipedOutNotification(row.getStatusBarNotification().getKey()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | final View veto = v.findViewById(R.id.veto); |
| 564 | if (veto != null && veto.getVisibility() != View.GONE) { |
| 565 | veto.performClick(); |
| 566 | } |
| 567 | if (DEBUG) Log.v(TAG, "onChildDismissed: " + v); |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 568 | |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 569 | mFalsingManager.onNotificationDismissed(); |
| 570 | if (mFalsingManager.shouldEnforceBouncer()) { |
Blazej Magnowski | 7232332 | 2015-07-24 11:49:40 -0700 | [diff] [blame] | 571 | mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null /* cancelAction */, |
| 572 | false /* dismissShade */, true /* afterKeyguardGone */); |
| 573 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void onChildSnappedBack(View animView) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 578 | mAmbientState.onDragFinished(animView); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 579 | if (!mDragAnimPendingChildren.contains(animView)) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 580 | if (mAnimationsEnabled) { |
| 581 | mSnappedBackChildren.add(animView); |
| 582 | mNeedsAnimation = true; |
| 583 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 584 | requestChildrenUpdate(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 585 | } else { |
| 586 | // We start the swipe and snap back in the same frame, we don't want any animation |
| 587 | mDragAnimPendingChildren.remove(animView); |
| 588 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 589 | } |
| 590 | |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 591 | @Override |
| 592 | public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) { |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 593 | if (!mIsExpanded && isPinnedHeadsUp(animView) && canChildBeDismissed(animView)) { |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 594 | mScrimController.setTopHeadsUpDragAmount(animView, |
| 595 | Math.min(Math.abs(swipeProgress - 1.0f), 1.0f)); |
| 596 | } |
Adrian Roos | 5d9cc66 | 2014-05-28 17:08:13 +0200 | [diff] [blame] | 597 | return false; |
| 598 | } |
| 599 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 600 | public void onBeginDrag(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 601 | mFalsingManager.onNotificatonStartDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 602 | setSwipingInProgress(true); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 603 | mAmbientState.onBeginDrag(v); |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 604 | if (mAnimationsEnabled && (mIsExpanded || !isPinnedHeadsUp(v))) { |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 605 | mDragAnimPendingChildren.add(v); |
| 606 | mNeedsAnimation = true; |
| 607 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 608 | requestChildrenUpdate(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 611 | public static boolean isPinnedHeadsUp(View v) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 612 | if (v instanceof ExpandableNotificationRow) { |
| 613 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 614 | return row.isHeadsUp() && row.isPinned(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 615 | } |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | private boolean isHeadsUp(View v) { |
| 620 | if (v instanceof ExpandableNotificationRow) { |
| 621 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 622 | return row.isHeadsUp(); |
| 623 | } |
| 624 | return false; |
| 625 | } |
| 626 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 627 | public void onDragCancelled(View v) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 628 | mFalsingManager.onNotificatonStopDismissing(); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 629 | setSwipingInProgress(false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 632 | @Override |
| 633 | public float getFalsingThresholdFactor() { |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 634 | return mPhoneStatusBar.isWakeUpComingFromTouch() ? 1.5f : 1.0f; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 637 | public View getChildAtPosition(MotionEvent ev) { |
| 638 | return getChildAtPosition(ev.getX(), ev.getY()); |
| 639 | } |
| 640 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 641 | public ExpandableView getClosestChildAtRawPosition(float touchX, float touchY) { |
| 642 | getLocationOnScreen(mTempInt2); |
| 643 | float localTouchY = touchY - mTempInt2[1]; |
| 644 | |
| 645 | ExpandableView closestChild = null; |
| 646 | float minDist = Float.MAX_VALUE; |
| 647 | |
| 648 | // find the view closest to the location, accounting for GONE views |
| 649 | final int count = getChildCount(); |
| 650 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 651 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
| 652 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame^] | 653 | || slidingChild instanceof StackScrollerDecorView) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 654 | continue; |
| 655 | } |
| 656 | float childTop = slidingChild.getTranslationY(); |
| 657 | float top = childTop + slidingChild.getClipTopAmount(); |
| 658 | float bottom = childTop + slidingChild.getActualHeight(); |
| 659 | |
| 660 | float dist = Math.min(Math.abs(top - localTouchY), Math.abs(bottom - localTouchY)); |
| 661 | if (dist < minDist) { |
| 662 | closestChild = slidingChild; |
| 663 | minDist = dist; |
| 664 | } |
| 665 | } |
| 666 | return closestChild; |
| 667 | } |
| 668 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 669 | public ExpandableView getChildAtRawPosition(float touchX, float touchY) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 670 | getLocationOnScreen(mTempInt2); |
| 671 | return getChildAtPosition(touchX - mTempInt2[0], touchY - mTempInt2[1]); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 674 | public ExpandableView getChildAtPosition(float touchX, float touchY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 675 | // find the view under the pointer, accounting for GONE views |
| 676 | final int count = getChildCount(); |
| 677 | for (int childIdx = 0; childIdx < count; childIdx++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 678 | ExpandableView slidingChild = (ExpandableView) getChildAt(childIdx); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 679 | if (slidingChild.getVisibility() == GONE |
Selim Cinek | 4fd5dfc | 2016-01-19 15:16:15 -0800 | [diff] [blame^] | 680 | || slidingChild instanceof StackScrollerDecorView) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 681 | continue; |
| 682 | } |
Selim Cinek | 89faff1 | 2014-06-19 16:29:04 -0700 | [diff] [blame] | 683 | float childTop = slidingChild.getTranslationY(); |
| 684 | float top = childTop + slidingChild.getClipTopAmount(); |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 685 | float bottom = childTop + slidingChild.getActualHeight(); |
Jorim Jaggi | 28f0e59 | 2014-08-05 22:03:07 +0200 | [diff] [blame] | 686 | |
| 687 | // Allow the full width of this view to prevent gesture conflict on Keyguard (phone and |
| 688 | // camera affordance). |
| 689 | int left = 0; |
| 690 | int right = getWidth(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 691 | |
| 692 | if (touchY >= top && touchY <= bottom && touchX >= left && touchX <= right) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 693 | if (slidingChild instanceof ExpandableNotificationRow) { |
| 694 | ExpandableNotificationRow row = (ExpandableNotificationRow) slidingChild; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 695 | if (!mIsExpanded && row.isHeadsUp() && row.isPinned() |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 696 | && mHeadsUpManager.getTopEntry().entry.row != row |
| 697 | && mGroupManager.getGroupSummary( |
| 698 | mHeadsUpManager.getTopEntry().entry.row.getStatusBarNotification()) |
| 699 | != row) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 700 | continue; |
| 701 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 702 | return row.getViewAtPosition(touchY - childTop); |
| 703 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 704 | return slidingChild; |
| 705 | } |
| 706 | } |
| 707 | return null; |
| 708 | } |
| 709 | |
| 710 | public boolean canChildBeExpanded(View v) { |
| 711 | return v instanceof ExpandableNotificationRow |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 712 | && ((ExpandableNotificationRow) v).isExpandable() |
| 713 | && !((ExpandableNotificationRow) v).isHeadsUp(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | public void setUserExpandedChild(View v, boolean userExpanded) { |
| 717 | if (v instanceof ExpandableNotificationRow) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 718 | ((ExpandableNotificationRow) v).setUserExpanded(userExpanded, |
| 719 | true /* allowChildrenExpansion */); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | public void setUserLockedChild(View v, boolean userLocked) { |
| 724 | if (v instanceof ExpandableNotificationRow) { |
| 725 | ((ExpandableNotificationRow) v).setUserLocked(userLocked); |
| 726 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 727 | removeLongPressCallback(); |
| 728 | requestDisallowInterceptTouchEvent(true); |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public void expansionStateChanged(boolean isExpanding) { |
| 733 | mExpandingNotification = isExpanding; |
| 734 | if (!mExpandedInThisMotion) { |
| 735 | mMaxScrollAfterExpand = mOwnScrollY; |
| 736 | mExpandedInThisMotion = true; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | public void setScrollingEnabled(boolean enable) { |
| 741 | mScrollingEnabled = enable; |
| 742 | } |
| 743 | |
| 744 | public void setExpandingEnabled(boolean enable) { |
| 745 | mExpandHelper.setEnabled(enable); |
| 746 | } |
| 747 | |
| 748 | private boolean isScrollingEnabled() { |
| 749 | return mScrollingEnabled; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | public View getChildContentView(View v) { |
| 753 | return v; |
| 754 | } |
| 755 | |
| 756 | public boolean canChildBeDismissed(View v) { |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 757 | return StackScrollAlgorithm.canChildBeDismissed(v); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 760 | @Override |
| 761 | public boolean isAntiFalsingNeeded() { |
Selim Cinek | cb2b673 | 2014-09-05 16:17:22 +0200 | [diff] [blame] | 762 | return mPhoneStatusBar.getBarState() == StatusBarState.KEYGUARD; |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 763 | } |
| 764 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 765 | private void setSwipingInProgress(boolean isSwiped) { |
| 766 | mSwipingInProgress = isSwiped; |
| 767 | if(isSwiped) { |
| 768 | requestDisallowInterceptTouchEvent(true); |
| 769 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | @Override |
| 773 | protected void onConfigurationChanged(Configuration newConfig) { |
| 774 | super.onConfigurationChanged(newConfig); |
| 775 | float densityScale = getResources().getDisplayMetrics().density; |
| 776 | mSwipeHelper.setDensityScale(densityScale); |
| 777 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 778 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 779 | initView(getContext()); |
| 780 | } |
| 781 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 782 | public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 783 | mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public boolean onTouchEvent(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 788 | boolean isCancelOrUp = ev.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 789 | || ev.getActionMasked()== MotionEvent.ACTION_UP; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 790 | if (mDelegateToScrollView) { |
| 791 | if (isCancelOrUp) { |
| 792 | mDelegateToScrollView = false; |
| 793 | } |
| 794 | transformTouchEvent(ev, this, mScrollView); |
| 795 | return mScrollView.onTouchEvent(ev); |
| 796 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 797 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 798 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 799 | if (mIsExpanded && !mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 800 | if (isCancelOrUp) { |
| 801 | mExpandHelper.onlyObserveMovements(false); |
| 802 | } |
| 803 | boolean wasExpandingBefore = mExpandingNotification; |
| 804 | expandWantsIt = mExpandHelper.onTouchEvent(ev); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 805 | if (mExpandedInThisMotion && !mExpandingNotification && wasExpandingBefore |
| 806 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 807 | dispatchDownEventToScroller(ev); |
| 808 | } |
| 809 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 810 | boolean scrollerWantsIt = false; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 811 | if (mIsExpanded && !mSwipingInProgress && !mExpandingNotification |
| 812 | && !mDisallowScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 813 | scrollerWantsIt = onScrollTouch(ev); |
| 814 | } |
| 815 | boolean horizontalSwipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 816 | if (!mIsBeingDragged |
| 817 | && !mExpandingNotification |
| 818 | && !mExpandedInThisMotion |
| 819 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 820 | horizontalSwipeWantsIt = mSwipeHelper.onTouchEvent(ev); |
| 821 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 822 | return horizontalSwipeWantsIt || scrollerWantsIt || expandWantsIt || super.onTouchEvent(ev); |
| 823 | } |
| 824 | |
| 825 | private void dispatchDownEventToScroller(MotionEvent ev) { |
| 826 | MotionEvent downEvent = MotionEvent.obtain(ev); |
| 827 | downEvent.setAction(MotionEvent.ACTION_DOWN); |
| 828 | onScrollTouch(downEvent); |
| 829 | downEvent.recycle(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | private boolean onScrollTouch(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 833 | if (!isScrollingEnabled()) { |
| 834 | return false; |
| 835 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 836 | initVelocityTrackerIfNotExists(); |
| 837 | mVelocityTracker.addMovement(ev); |
| 838 | |
| 839 | final int action = ev.getAction(); |
| 840 | |
| 841 | switch (action & MotionEvent.ACTION_MASK) { |
| 842 | case MotionEvent.ACTION_DOWN: { |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 843 | if (getChildCount() == 0 || !isInContentBounds(ev)) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 844 | return false; |
| 845 | } |
| 846 | boolean isBeingDragged = !mScroller.isFinished(); |
| 847 | setIsBeingDragged(isBeingDragged); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 848 | |
| 849 | /* |
| 850 | * If being flinged and user touches, stop the fling. isFinished |
| 851 | * will be false if being flinged. |
| 852 | */ |
| 853 | if (!mScroller.isFinished()) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 854 | mScroller.forceFinished(true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | // Remember where the motion event started |
| 858 | mLastMotionY = (int) ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 859 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 860 | mActivePointerId = ev.getPointerId(0); |
| 861 | break; |
| 862 | } |
| 863 | case MotionEvent.ACTION_MOVE: |
| 864 | final int activePointerIndex = ev.findPointerIndex(mActivePointerId); |
| 865 | if (activePointerIndex == -1) { |
| 866 | Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent"); |
| 867 | break; |
| 868 | } |
| 869 | |
| 870 | final int y = (int) ev.getY(activePointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 871 | final int x = (int) ev.getX(activePointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 872 | int deltaY = mLastMotionY - y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 873 | final int xDiff = Math.abs(x - mDownX); |
| 874 | final int yDiff = Math.abs(deltaY); |
| 875 | if (!mIsBeingDragged && yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 876 | setIsBeingDragged(true); |
| 877 | if (deltaY > 0) { |
| 878 | deltaY -= mTouchSlop; |
| 879 | } else { |
| 880 | deltaY += mTouchSlop; |
| 881 | } |
| 882 | } |
| 883 | if (mIsBeingDragged) { |
| 884 | // Scroll to follow the motion event |
| 885 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 886 | int range = getScrollRange(); |
| 887 | if (mExpandedInThisMotion) { |
| 888 | range = Math.min(range, mMaxScrollAfterExpand); |
| 889 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 890 | |
| 891 | float scrollAmount; |
| 892 | if (deltaY < 0) { |
| 893 | scrollAmount = overScrollDown(deltaY); |
| 894 | } else { |
| 895 | scrollAmount = overScrollUp(deltaY, range); |
| 896 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 897 | |
| 898 | // Calling overScrollBy will call onOverScrolled, which |
| 899 | // calls onScrollChanged if applicable. |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 900 | if (scrollAmount != 0.0f) { |
| 901 | // The scrolling motion could not be compensated with the |
| 902 | // existing overScroll, we have to scroll the view |
| 903 | overScrollBy(0, (int) scrollAmount, 0, mOwnScrollY, |
| 904 | 0, range, 0, getHeight() / 2, true); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 905 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 906 | } |
| 907 | break; |
| 908 | case MotionEvent.ACTION_UP: |
| 909 | if (mIsBeingDragged) { |
| 910 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 911 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 912 | int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); |
| 913 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 914 | if (shouldOverScrollFling(initialVelocity)) { |
| 915 | onOverScrollFling(true, initialVelocity); |
| 916 | } else { |
| 917 | if (getChildCount() > 0) { |
| 918 | if ((Math.abs(initialVelocity) > mMinimumVelocity)) { |
| 919 | float currentOverScrollTop = getCurrentOverScrollAmount(true); |
| 920 | if (currentOverScrollTop == 0.0f || initialVelocity > 0) { |
| 921 | fling(-initialVelocity); |
| 922 | } else { |
| 923 | onOverScrollFling(false, initialVelocity); |
| 924 | } |
| 925 | } else { |
| 926 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, |
| 927 | getScrollRange())) { |
| 928 | postInvalidateOnAnimation(); |
| 929 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 930 | } |
| 931 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 932 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 933 | |
| 934 | mActivePointerId = INVALID_POINTER; |
| 935 | endDrag(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 936 | } |
Selim Cinek | 48e746c | 2014-06-16 16:01:03 -0700 | [diff] [blame] | 937 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 938 | break; |
| 939 | case MotionEvent.ACTION_CANCEL: |
| 940 | if (mIsBeingDragged && getChildCount() > 0) { |
| 941 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 942 | postInvalidateOnAnimation(); |
| 943 | } |
| 944 | mActivePointerId = INVALID_POINTER; |
| 945 | endDrag(); |
| 946 | } |
| 947 | break; |
| 948 | case MotionEvent.ACTION_POINTER_DOWN: { |
| 949 | final int index = ev.getActionIndex(); |
| 950 | mLastMotionY = (int) ev.getY(index); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 951 | mDownX = (int) ev.getX(index); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 952 | mActivePointerId = ev.getPointerId(index); |
| 953 | break; |
| 954 | } |
| 955 | case MotionEvent.ACTION_POINTER_UP: |
| 956 | onSecondaryPointerUp(ev); |
| 957 | mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 958 | mDownX = (int) ev.getX(ev.findPointerIndex(mActivePointerId)); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 959 | break; |
| 960 | } |
| 961 | return true; |
| 962 | } |
| 963 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 964 | private void onOverScrollFling(boolean open, int initialVelocity) { |
| 965 | if (mOverscrollTopChangedListener != null) { |
| 966 | mOverscrollTopChangedListener.flingTopOverscroll(initialVelocity, open); |
| 967 | } |
| 968 | mDontReportNextOverScroll = true; |
| 969 | setOverScrollAmount(0.0f, true, false); |
| 970 | } |
| 971 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 972 | /** |
| 973 | * Perform a scroll upwards and adapt the overscroll amounts accordingly |
| 974 | * |
| 975 | * @param deltaY The amount to scroll upwards, has to be positive. |
| 976 | * @return The amount of scrolling to be performed by the scroller, |
| 977 | * not handled by the overScroll amount. |
| 978 | */ |
| 979 | private float overScrollUp(int deltaY, int range) { |
| 980 | deltaY = Math.max(deltaY, 0); |
| 981 | float currentTopAmount = getCurrentOverScrollAmount(true); |
| 982 | float newTopAmount = currentTopAmount - deltaY; |
| 983 | if (currentTopAmount > 0) { |
| 984 | setOverScrollAmount(newTopAmount, true /* onTop */, |
| 985 | false /* animate */); |
| 986 | } |
| 987 | // Top overScroll might not grab all scrolling motion, |
| 988 | // we have to scroll as well. |
| 989 | float scrollAmount = newTopAmount < 0 ? -newTopAmount : 0.0f; |
| 990 | float newScrollY = mOwnScrollY + scrollAmount; |
| 991 | if (newScrollY > range) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 992 | if (!mExpandedInThisMotion) { |
| 993 | float currentBottomPixels = getCurrentOverScrolledPixels(false); |
| 994 | // We overScroll on the top |
| 995 | setOverScrolledPixels(currentBottomPixels + newScrollY - range, |
| 996 | false /* onTop */, |
| 997 | false /* animate */); |
| 998 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 999 | mOwnScrollY = range; |
| 1000 | scrollAmount = 0.0f; |
| 1001 | } |
| 1002 | return scrollAmount; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * Perform a scroll downward and adapt the overscroll amounts accordingly |
| 1007 | * |
| 1008 | * @param deltaY The amount to scroll downwards, has to be negative. |
| 1009 | * @return The amount of scrolling to be performed by the scroller, |
| 1010 | * not handled by the overScroll amount. |
| 1011 | */ |
| 1012 | private float overScrollDown(int deltaY) { |
| 1013 | deltaY = Math.min(deltaY, 0); |
| 1014 | float currentBottomAmount = getCurrentOverScrollAmount(false); |
| 1015 | float newBottomAmount = currentBottomAmount + deltaY; |
| 1016 | if (currentBottomAmount > 0) { |
| 1017 | setOverScrollAmount(newBottomAmount, false /* onTop */, |
| 1018 | false /* animate */); |
| 1019 | } |
| 1020 | // Bottom overScroll might not grab all scrolling motion, |
| 1021 | // we have to scroll as well. |
| 1022 | float scrollAmount = newBottomAmount < 0 ? newBottomAmount : 0.0f; |
| 1023 | float newScrollY = mOwnScrollY + scrollAmount; |
| 1024 | if (newScrollY < 0) { |
| 1025 | float currentTopPixels = getCurrentOverScrolledPixels(true); |
| 1026 | // We overScroll on the top |
| 1027 | setOverScrolledPixels(currentTopPixels - newScrollY, |
| 1028 | true /* onTop */, |
| 1029 | false /* animate */); |
| 1030 | mOwnScrollY = 0; |
| 1031 | scrollAmount = 0.0f; |
| 1032 | } |
| 1033 | return scrollAmount; |
| 1034 | } |
| 1035 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1036 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 1037 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 1038 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 1039 | final int pointerId = ev.getPointerId(pointerIndex); |
| 1040 | if (pointerId == mActivePointerId) { |
| 1041 | // This was our active pointer going up. Choose a new |
| 1042 | // active pointer and adjust accordingly. |
| 1043 | // TODO: Make this decision more intelligent. |
| 1044 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 1045 | mLastMotionY = (int) ev.getY(newPointerIndex); |
| 1046 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 1047 | if (mVelocityTracker != null) { |
| 1048 | mVelocityTracker.clear(); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | private void initVelocityTrackerIfNotExists() { |
| 1054 | if (mVelocityTracker == null) { |
| 1055 | mVelocityTracker = VelocityTracker.obtain(); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | private void recycleVelocityTracker() { |
| 1060 | if (mVelocityTracker != null) { |
| 1061 | mVelocityTracker.recycle(); |
| 1062 | mVelocityTracker = null; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | private void initOrResetVelocityTracker() { |
| 1067 | if (mVelocityTracker == null) { |
| 1068 | mVelocityTracker = VelocityTracker.obtain(); |
| 1069 | } else { |
| 1070 | mVelocityTracker.clear(); |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | @Override |
| 1075 | public void computeScroll() { |
| 1076 | if (mScroller.computeScrollOffset()) { |
| 1077 | // This is called at drawing time by ViewGroup. |
| 1078 | int oldX = mScrollX; |
| 1079 | int oldY = mOwnScrollY; |
| 1080 | int x = mScroller.getCurrX(); |
| 1081 | int y = mScroller.getCurrY(); |
| 1082 | |
| 1083 | if (oldX != x || oldY != y) { |
| 1084 | final int range = getScrollRange(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1085 | if (y < 0 && oldY >= 0 || y > range && oldY <= range) { |
| 1086 | float currVelocity = mScroller.getCurrVelocity(); |
Selim Cinek | ba81962 | 2014-05-13 17:55:53 +0200 | [diff] [blame] | 1087 | if (currVelocity >= mMinimumVelocity) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1088 | mMaxOverScroll = Math.abs(currVelocity) / 1000 * mOverflingDistance; |
| 1089 | } |
| 1090 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1091 | |
| 1092 | overScrollBy(x - oldX, y - oldY, oldX, oldY, 0, range, |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1093 | 0, (int) (mMaxOverScroll), false); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1094 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | // Keep on drawing until the animation has finished. |
| 1098 | postInvalidateOnAnimation(); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1102 | @Override |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1103 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 1104 | int scrollX, int scrollY, |
| 1105 | int scrollRangeX, int scrollRangeY, |
| 1106 | int maxOverScrollX, int maxOverScrollY, |
| 1107 | boolean isTouchEvent) { |
| 1108 | |
| 1109 | int newScrollY = scrollY + deltaY; |
| 1110 | |
| 1111 | final int top = -maxOverScrollY; |
| 1112 | final int bottom = maxOverScrollY + scrollRangeY; |
| 1113 | |
| 1114 | boolean clampedY = false; |
| 1115 | if (newScrollY > bottom) { |
| 1116 | newScrollY = bottom; |
| 1117 | clampedY = true; |
| 1118 | } else if (newScrollY < top) { |
| 1119 | newScrollY = top; |
| 1120 | clampedY = true; |
| 1121 | } |
| 1122 | |
| 1123 | onOverScrolled(0, newScrollY, false, clampedY); |
| 1124 | |
| 1125 | return clampedY; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Set the amount of overScrolled pixels which will force the view to apply a rubber-banded |
| 1130 | * overscroll effect based on numPixels. By default this will also cancel animations on the |
| 1131 | * same overScroll edge. |
| 1132 | * |
| 1133 | * @param numPixels The amount of pixels to overScroll by. These will be scaled according to |
| 1134 | * the rubber-banding logic. |
| 1135 | * @param onTop Should the effect be applied on top of the scroller. |
| 1136 | * @param animate Should an animation be performed. |
| 1137 | */ |
| 1138 | public void setOverScrolledPixels(float numPixels, boolean onTop, boolean animate) { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1139 | setOverScrollAmount(numPixels * getRubberBandFactor(onTop), onTop, animate, true); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1144 | * By default this will also cancel animations on the same overScroll edge. |
| 1145 | * |
| 1146 | * @param amount The amount to overScroll by. |
| 1147 | * @param onTop Should the effect be applied on top of the scroller. |
| 1148 | * @param animate Should an animation be performed. |
| 1149 | */ |
| 1150 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate) { |
| 1151 | setOverScrollAmount(amount, onTop, animate, true); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1156 | * |
| 1157 | * @param amount The amount to overScroll by. |
| 1158 | * @param onTop Should the effect be applied on top of the scroller. |
| 1159 | * @param animate Should an animation be performed. |
| 1160 | * @param cancelAnimators Should running animations be cancelled. |
| 1161 | */ |
| 1162 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1163 | boolean cancelAnimators) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1164 | setOverScrollAmount(amount, onTop, animate, cancelAnimators, isRubberbanded(onTop)); |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Set the effective overScroll amount which will be directly reflected in the layout. |
| 1169 | * |
| 1170 | * @param amount The amount to overScroll by. |
| 1171 | * @param onTop Should the effect be applied on top of the scroller. |
| 1172 | * @param animate Should an animation be performed. |
| 1173 | * @param cancelAnimators Should running animations be cancelled. |
| 1174 | * @param isRubberbanded The value which will be passed to |
| 1175 | * {@link OnOverscrollTopChangedListener#onOverscrollTopChanged} |
| 1176 | */ |
| 1177 | public void setOverScrollAmount(float amount, boolean onTop, boolean animate, |
| 1178 | boolean cancelAnimators, boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1179 | if (cancelAnimators) { |
| 1180 | mStateAnimator.cancelOverScrollAnimators(onTop); |
| 1181 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1182 | setOverScrollAmountInternal(amount, onTop, animate, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1185 | private void setOverScrollAmountInternal(float amount, boolean onTop, boolean animate, |
| 1186 | boolean isRubberbanded) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1187 | amount = Math.max(0, amount); |
| 1188 | if (animate) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1189 | mStateAnimator.animateOverScrollToAmount(amount, onTop, isRubberbanded); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1190 | } else { |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1191 | setOverScrolledPixels(amount / getRubberBandFactor(onTop), onTop); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1192 | mAmbientState.setOverScrollAmount(amount, onTop); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1193 | if (onTop) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1194 | notifyOverscrollTopListener(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1195 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1196 | requestChildrenUpdate(); |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1200 | private void notifyOverscrollTopListener(float amount, boolean isRubberbanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1201 | mExpandHelper.onlyObserveMovements(amount > 1.0f); |
| 1202 | if (mDontReportNextOverScroll) { |
| 1203 | mDontReportNextOverScroll = false; |
| 1204 | return; |
| 1205 | } |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1206 | if (mOverscrollTopChangedListener != null) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1207 | mOverscrollTopChangedListener.onOverscrollTopChanged(amount, isRubberbanded); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | public void setOverscrollTopChangedListener( |
| 1212 | OnOverscrollTopChangedListener overscrollTopChangedListener) { |
| 1213 | mOverscrollTopChangedListener = overscrollTopChangedListener; |
| 1214 | } |
| 1215 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1216 | public float getCurrentOverScrollAmount(boolean top) { |
| 1217 | return mAmbientState.getOverScrollAmount(top); |
| 1218 | } |
| 1219 | |
| 1220 | public float getCurrentOverScrolledPixels(boolean top) { |
| 1221 | return top? mOverScrolledTopPixels : mOverScrolledBottomPixels; |
| 1222 | } |
| 1223 | |
| 1224 | private void setOverScrolledPixels(float amount, boolean onTop) { |
| 1225 | if (onTop) { |
| 1226 | mOverScrolledTopPixels = amount; |
| 1227 | } else { |
| 1228 | mOverScrolledBottomPixels = amount; |
| 1229 | } |
| 1230 | } |
| 1231 | |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1232 | private void customScrollTo(int y) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1233 | mOwnScrollY = y; |
Selim Cinek | 3af00cf | 2014-05-07 17:27:26 +0200 | [diff] [blame] | 1234 | updateChildren(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | @Override |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 1238 | protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1239 | // Treat animating scrolls differently; see #computeScroll() for why. |
| 1240 | if (!mScroller.isFinished()) { |
| 1241 | final int oldX = mScrollX; |
| 1242 | final int oldY = mOwnScrollY; |
| 1243 | mScrollX = scrollX; |
| 1244 | mOwnScrollY = scrollY; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1245 | if (clampedY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1246 | springBack(); |
| 1247 | } else { |
| 1248 | onScrollChanged(mScrollX, mOwnScrollY, oldX, oldY); |
| 1249 | invalidateParentIfNeeded(); |
| 1250 | updateChildren(); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1251 | float overScrollTop = getCurrentOverScrollAmount(true); |
| 1252 | if (mOwnScrollY < 0) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1253 | notifyOverscrollTopListener(-mOwnScrollY, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1254 | } else { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1255 | notifyOverscrollTopListener(overScrollTop, isRubberbanded(true)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 1256 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1257 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1258 | } else { |
| 1259 | customScrollTo(scrollY); |
| 1260 | scrollTo(scrollX, mScrollY); |
| 1261 | } |
| 1262 | } |
| 1263 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1264 | private void springBack() { |
| 1265 | int scrollRange = getScrollRange(); |
| 1266 | boolean overScrolledTop = mOwnScrollY <= 0; |
| 1267 | boolean overScrolledBottom = mOwnScrollY >= scrollRange; |
| 1268 | if (overScrolledTop || overScrolledBottom) { |
| 1269 | boolean onTop; |
| 1270 | float newAmount; |
| 1271 | if (overScrolledTop) { |
| 1272 | onTop = true; |
| 1273 | newAmount = -mOwnScrollY; |
| 1274 | mOwnScrollY = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1275 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1276 | } else { |
| 1277 | onTop = false; |
| 1278 | newAmount = mOwnScrollY - scrollRange; |
| 1279 | mOwnScrollY = scrollRange; |
| 1280 | } |
| 1281 | setOverScrollAmount(newAmount, onTop, false); |
| 1282 | setOverScrollAmount(0.0f, onTop, true); |
| 1283 | mScroller.forceFinished(true); |
| 1284 | } |
| 1285 | } |
| 1286 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1287 | private int getScrollRange() { |
| 1288 | int scrollRange = 0; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1289 | ExpandableView firstChild = (ExpandableView) getFirstChildNotGone(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1290 | if (firstChild != null) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1291 | int contentHeight = getContentHeight(); |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 1292 | scrollRange = Math.max(0, contentHeight - mMaxLayoutHeight + mBottomStackPeekSize |
| 1293 | + mBottomStackSlowDownHeight); |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1294 | if (scrollRange > 0) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1295 | int firstChildMaxExpandHeight = getMaxExpandHeight(firstChild); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1296 | // We want to at least be able collapse the first item and not ending in a weird |
| 1297 | // end state. |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1298 | scrollRange = Math.max(scrollRange, firstChildMaxExpandHeight |
| 1299 | - firstChild.getMinHeight()); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1300 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1301 | } |
| 1302 | return scrollRange; |
| 1303 | } |
| 1304 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1305 | /** |
| 1306 | * @return the first child which has visibility unequal to GONE |
| 1307 | */ |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1308 | public ExpandableView getFirstChildNotGone() { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1309 | int childCount = getChildCount(); |
| 1310 | for (int i = 0; i < childCount; i++) { |
| 1311 | View child = getChildAt(i); |
| 1312 | if (child.getVisibility() != View.GONE) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1313 | return (ExpandableView) child; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | return null; |
| 1317 | } |
| 1318 | |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1319 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1320 | * @return The first child which has visibility unequal to GONE which is currently below the |
| 1321 | * given translationY or equal to it. |
| 1322 | */ |
| 1323 | private View getFirstChildBelowTranlsationY(float translationY) { |
| 1324 | int childCount = getChildCount(); |
| 1325 | for (int i = 0; i < childCount; i++) { |
| 1326 | View child = getChildAt(i); |
| 1327 | if (child.getVisibility() != View.GONE && child.getTranslationY() >= translationY) { |
| 1328 | return child; |
| 1329 | } |
| 1330 | } |
| 1331 | return null; |
| 1332 | } |
| 1333 | |
| 1334 | /** |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1335 | * @return the last child which has visibility unequal to GONE |
| 1336 | */ |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1337 | public View getLastChildNotGone() { |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 1338 | int childCount = getChildCount(); |
| 1339 | for (int i = childCount - 1; i >= 0; i--) { |
| 1340 | View child = getChildAt(i); |
| 1341 | if (child.getVisibility() != View.GONE) { |
| 1342 | return child; |
| 1343 | } |
| 1344 | } |
| 1345 | return null; |
| 1346 | } |
| 1347 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1348 | /** |
| 1349 | * @return the number of children which have visibility unequal to GONE |
| 1350 | */ |
| 1351 | public int getNotGoneChildCount() { |
| 1352 | int childCount = getChildCount(); |
| 1353 | int count = 0; |
| 1354 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 1355 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 1356 | if (child.getVisibility() != View.GONE && !child.willBeGone()) { |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 1357 | count++; |
| 1358 | } |
| 1359 | } |
| 1360 | return count; |
| 1361 | } |
| 1362 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1363 | private int getMaxExpandHeight(View view) { |
| 1364 | if (view instanceof ExpandableNotificationRow) { |
| 1365 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 1366 | return row.getIntrinsicHeight(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1367 | } |
| 1368 | return view.getHeight(); |
| 1369 | } |
| 1370 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1371 | public int getContentHeight() { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1372 | return mContentHeight; |
| 1373 | } |
| 1374 | |
| 1375 | private void updateContentHeight() { |
| 1376 | int height = 0; |
| 1377 | for (int i = 0; i < getChildCount(); i++) { |
| 1378 | View child = getChildAt(i); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1379 | if (child.getVisibility() != View.GONE) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1380 | if (height != 0) { |
| 1381 | // add the padding before this element |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1382 | height += mPaddingBetweenElements; |
| 1383 | } |
Selim Cinek | e53e6bb | 2015-04-13 16:14:26 -0700 | [diff] [blame] | 1384 | if (child instanceof ExpandableView) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1385 | ExpandableView expandableView = (ExpandableView) child; |
Selim Cinek | e53e6bb | 2015-04-13 16:14:26 -0700 | [diff] [blame] | 1386 | height += expandableView.getIntrinsicHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1387 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1388 | } |
| 1389 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 1390 | mContentHeight = height + mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * Fling the scroll view |
| 1395 | * |
| 1396 | * @param velocityY The initial velocity in the Y direction. Positive |
| 1397 | * numbers mean that the finger/cursor is moving down the screen, |
| 1398 | * which means we want to scroll towards the top. |
| 1399 | */ |
| 1400 | private void fling(int velocityY) { |
| 1401 | if (getChildCount() > 0) { |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1402 | int scrollRange = getScrollRange(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1403 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1404 | float topAmount = getCurrentOverScrollAmount(true); |
| 1405 | float bottomAmount = getCurrentOverScrollAmount(false); |
| 1406 | if (velocityY < 0 && topAmount > 0) { |
| 1407 | mOwnScrollY -= (int) topAmount; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1408 | mDontReportNextOverScroll = true; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1409 | setOverScrollAmount(0, true, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1410 | mMaxOverScroll = Math.abs(velocityY) / 1000f * getRubberBandFactor(true /* onTop */) |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1411 | * mOverflingDistance + topAmount; |
| 1412 | } else if (velocityY > 0 && bottomAmount > 0) { |
| 1413 | mOwnScrollY += bottomAmount; |
| 1414 | setOverScrollAmount(0, false, false); |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1415 | mMaxOverScroll = Math.abs(velocityY) / 1000f |
| 1416 | * getRubberBandFactor(false /* onTop */) * mOverflingDistance |
| 1417 | + bottomAmount; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1418 | } else { |
| 1419 | // it will be set once we reach the boundary |
| 1420 | mMaxOverScroll = 0.0f; |
| 1421 | } |
| 1422 | mScroller.fling(mScrollX, mOwnScrollY, 1, velocityY, 0, 0, 0, |
Selim Cinek | 4195dd0 | 2014-05-19 18:16:14 +0200 | [diff] [blame] | 1423 | Math.max(0, scrollRange), 0, Integer.MAX_VALUE / 2); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1424 | |
| 1425 | postInvalidateOnAnimation(); |
| 1426 | } |
| 1427 | } |
| 1428 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1429 | /** |
| 1430 | * @return Whether a fling performed on the top overscroll edge lead to the expanded |
| 1431 | * overScroll view (i.e QS). |
| 1432 | */ |
| 1433 | private boolean shouldOverScrollFling(int initialVelocity) { |
| 1434 | float topOverScroll = getCurrentOverScrollAmount(true); |
| 1435 | return mScrolledToTopOnFirstDown |
| 1436 | && !mExpandedInThisMotion |
| 1437 | && topOverScroll > mMinTopOverScrollToEscape |
| 1438 | && initialVelocity > 0; |
| 1439 | } |
| 1440 | |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1441 | /** |
| 1442 | * Updates the top padding of the notifications, taking {@link #getIntrinsicPadding()} into |
| 1443 | * account. |
| 1444 | * |
| 1445 | * @param qsHeight the top padding imposed by the quick settings panel |
| 1446 | * @param scrollY how much the notifications are scrolled inside the QS/notifications scroll |
| 1447 | * container |
| 1448 | * @param animate whether to animate the change |
| 1449 | * @param ignoreIntrinsicPadding if true, {@link #getIntrinsicPadding()} is ignored and |
| 1450 | * {@code qsHeight} is the final top padding |
| 1451 | */ |
| 1452 | public void updateTopPadding(float qsHeight, int scrollY, boolean animate, |
| 1453 | boolean ignoreIntrinsicPadding) { |
Selim Cinek | 33d4614 | 2016-01-15 18:58:39 -0800 | [diff] [blame] | 1454 | float start = qsHeight - scrollY; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1455 | float stackHeight = getHeight() - start; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1456 | int minStackHeight = getMinStackHeight(); |
| 1457 | if (stackHeight <= minStackHeight) { |
| 1458 | float overflow = minStackHeight - stackHeight; |
| 1459 | stackHeight = minStackHeight; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1460 | start = getHeight() - stackHeight; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1461 | mTopPaddingOverflow = overflow; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1462 | } else { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1463 | mTopPaddingOverflow = 0; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1464 | } |
Jorim Jaggi | 06a0c3a | 2014-10-29 17:17:21 +0100 | [diff] [blame] | 1465 | setTopPadding(ignoreIntrinsicPadding ? (int) start : clampPadding((int) start), |
| 1466 | animate); |
| 1467 | setStackHeight(mLastSetStackHeight); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1470 | public int getMinStackHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1471 | final ExpandableView firstChild = getFirstChildNotGone(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1472 | final int firstChildMinHeight = firstChild != null ? firstChild.getMinHeight() |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1473 | : mCollapsedSize; |
| 1474 | return firstChildMinHeight + mBottomStackPeekSize + mCollapseSecondCardPadding; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | public float getTopPaddingOverflow() { |
| 1478 | return mTopPaddingOverflow; |
| 1479 | } |
| 1480 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1481 | public int getPeekHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1482 | final ExpandableView firstChild = getFirstChildNotGone(); |
| 1483 | final int firstChildMinHeight = firstChild != null ? (int) firstChild.getMinHeight() |
| 1484 | : mCollapsedSize; |
| 1485 | return mIntrinsicPadding + firstChildMinHeight + mBottomStackPeekSize |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 1486 | + mCollapseSecondCardPadding; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1489 | private int clampPadding(int desiredPadding) { |
| 1490 | return Math.max(desiredPadding, mIntrinsicPadding); |
| 1491 | } |
| 1492 | |
Selim Cinek | fed1ab6 | 2014-06-17 14:10:33 -0700 | [diff] [blame] | 1493 | private float getRubberBandFactor(boolean onTop) { |
| 1494 | if (!onTop) { |
| 1495 | return RUBBER_BAND_FACTOR_NORMAL; |
| 1496 | } |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1497 | if (mExpandedInThisMotion) { |
| 1498 | return RUBBER_BAND_FACTOR_AFTER_EXPAND; |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 1499 | } else if (mIsExpansionChanging || mPanelTracking) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1500 | return RUBBER_BAND_FACTOR_ON_PANEL_EXPAND; |
| 1501 | } else if (mScrolledToTopOnFirstDown) { |
| 1502 | return 1.0f; |
| 1503 | } |
| 1504 | return RUBBER_BAND_FACTOR_NORMAL; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1505 | } |
| 1506 | |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1507 | /** |
| 1508 | * Accompanying function for {@link #getRubberBandFactor}: Returns true if the overscroll is |
| 1509 | * rubberbanded, false if it is technically an overscroll but rather a motion to expand the |
| 1510 | * overscroll view (e.g. expand QS). |
| 1511 | */ |
| 1512 | private boolean isRubberbanded(boolean onTop) { |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 1513 | return !onTop || mExpandedInThisMotion || mIsExpansionChanging || mPanelTracking |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 1514 | || !mScrolledToTopOnFirstDown; |
| 1515 | } |
| 1516 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1517 | private void endDrag() { |
| 1518 | setIsBeingDragged(false); |
| 1519 | |
| 1520 | recycleVelocityTracker(); |
| 1521 | |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 1522 | if (getCurrentOverScrollAmount(true /* onTop */) > 0) { |
| 1523 | setOverScrollAmount(0, true /* onTop */, true /* animate */); |
| 1524 | } |
| 1525 | if (getCurrentOverScrollAmount(false /* onTop */) > 0) { |
| 1526 | setOverScrollAmount(0, false /* onTop */, true /* animate */); |
| 1527 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1530 | private void transformTouchEvent(MotionEvent ev, View sourceView, View targetView) { |
| 1531 | ev.offsetLocation(sourceView.getX(), sourceView.getY()); |
| 1532 | ev.offsetLocation(-targetView.getX(), -targetView.getY()); |
| 1533 | } |
| 1534 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1535 | @Override |
| 1536 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1537 | if (mInterceptDelegateEnabled) { |
| 1538 | transformTouchEvent(ev, this, mScrollView); |
| 1539 | if (mScrollView.onInterceptTouchEvent(ev)) { |
| 1540 | mDelegateToScrollView = true; |
| 1541 | removeLongPressCallback(); |
| 1542 | return true; |
| 1543 | } |
| 1544 | transformTouchEvent(ev, mScrollView, this); |
| 1545 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1546 | initDownStates(ev); |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1547 | handleEmptySpaceClick(ev); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1548 | boolean expandWantsIt = false; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 1549 | if (!mSwipingInProgress && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1550 | expandWantsIt = mExpandHelper.onInterceptTouchEvent(ev); |
| 1551 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1552 | boolean scrollWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1553 | if (!mSwipingInProgress && !mExpandingNotification) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1554 | scrollWantsIt = onInterceptTouchEventScroll(ev); |
| 1555 | } |
| 1556 | boolean swipeWantsIt = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1557 | if (!mIsBeingDragged |
| 1558 | && !mExpandingNotification |
| 1559 | && !mExpandedInThisMotion |
| 1560 | && !mOnlyScrollingInThisMotion) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1561 | swipeWantsIt = mSwipeHelper.onInterceptTouchEvent(ev); |
| 1562 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1563 | return swipeWantsIt || scrollWantsIt || expandWantsIt || super.onInterceptTouchEvent(ev); |
| 1564 | } |
| 1565 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1566 | private void handleEmptySpaceClick(MotionEvent ev) { |
| 1567 | switch (ev.getActionMasked()) { |
| 1568 | case MotionEvent.ACTION_MOVE: |
| 1569 | if (mTouchIsClick && (Math.abs(ev.getY() - mInitialTouchY) > mTouchSlop |
| 1570 | || Math.abs(ev.getX() - mInitialTouchX) > mTouchSlop )) { |
| 1571 | mTouchIsClick = false; |
| 1572 | } |
| 1573 | break; |
| 1574 | case MotionEvent.ACTION_UP: |
| 1575 | if (mPhoneStatusBar.getBarState() != StatusBarState.KEYGUARD && mTouchIsClick && |
| 1576 | isBelowLastNotification(mInitialTouchX, mInitialTouchY)) { |
| 1577 | mOnEmptySpaceClickListener.onEmptySpaceClicked(mInitialTouchX, mInitialTouchY); |
| 1578 | } |
| 1579 | break; |
| 1580 | } |
| 1581 | } |
| 1582 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1583 | private void initDownStates(MotionEvent ev) { |
| 1584 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 1585 | mExpandedInThisMotion = false; |
| 1586 | mOnlyScrollingInThisMotion = !mScroller.isFinished(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 1587 | mDisallowScrollingInThisMotion = false; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 1588 | mTouchIsClick = true; |
| 1589 | mInitialTouchX = ev.getX(); |
| 1590 | mInitialTouchY = ev.getY(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1591 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1594 | public void setChildTransferInProgress(boolean childTransferInProgress) { |
| 1595 | mChildTransferInProgress = childTransferInProgress; |
| 1596 | } |
| 1597 | |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1598 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 1599 | public void onViewRemoved(View child) { |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1600 | super.onViewRemoved(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1601 | // we only call our internal methods if this is actually a removal and not just a |
| 1602 | // notification which becomes a child notification |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1603 | if (!mChildTransferInProgress) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1604 | onViewRemovedInternal(child); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | private void onViewRemovedInternal(View child) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1609 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1610 | if (mChangePositionInProgress) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1611 | // This is only a position change, don't do anything special |
| 1612 | return; |
| 1613 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1614 | ((ExpandableView) child).setOnHeightChangedListener(null); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 1615 | mCurrentStackScrollState.removeViewStateForView(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1616 | updateScrollStateForRemovedChild(child); |
Selim Cinek | 2aab2fb | 2015-04-15 18:47:01 -0700 | [diff] [blame] | 1617 | boolean animationGenerated = generateRemoveAnimation(child); |
| 1618 | if (animationGenerated && !mSwipedOutViews.contains(child)) { |
| 1619 | // Add this view to an overlay in order to ensure that it will still be temporary |
| 1620 | // drawn when removed |
| 1621 | getOverlay().add(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1622 | } |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1623 | updateAnimationState(false, child); |
Selim Cinek | c0f4c01 | 2014-08-25 15:45:33 +0200 | [diff] [blame] | 1624 | |
| 1625 | // Make sure the clipRect we might have set is removed |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 1626 | ((ExpandableView) child).setClipTopOptimization(0); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1629 | private boolean isChildInGroup(View child) { |
| 1630 | return child instanceof ExpandableNotificationRow |
| 1631 | && mGroupManager.isChildInGroupWithSummary( |
| 1632 | ((ExpandableNotificationRow) child).getStatusBarNotification()); |
| 1633 | } |
| 1634 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1635 | /** |
| 1636 | * Generate a remove animation for a child view. |
| 1637 | * |
| 1638 | * @param child The view to generate the remove animation for. |
| 1639 | * @return Whether an animation was generated. |
| 1640 | */ |
| 1641 | private boolean generateRemoveAnimation(View child) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 1642 | if (removeRemovedChildFromHeadsUpChangeAnimations(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 1643 | mAddedHeadsUpChildren.remove(child); |
| 1644 | return false; |
| 1645 | } |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 1646 | if (isClickedHeadsUp(child)) { |
| 1647 | // An animation is already running, add it to the Overlay |
| 1648 | mClearOverlayViewsWhenFinished.add(child); |
| 1649 | return true; |
| 1650 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1651 | if (mIsExpanded && mAnimationsEnabled && !isChildInInvisibleGroup(child)) { |
Selim Cinek | 233241f | 2015-06-01 06:11:19 -0700 | [diff] [blame] | 1652 | if (!mChildrenToAddAnimated.contains(child)) { |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1653 | // Generate Animations |
| 1654 | mChildrenToRemoveAnimated.add(child); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1655 | mNeedsAnimation = true; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1656 | return true; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1657 | } else { |
| 1658 | mChildrenToAddAnimated.remove(child); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 1659 | mFromMoreCardAdditions.remove(child); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1660 | return false; |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1661 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1662 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1663 | return false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 1666 | private boolean isClickedHeadsUp(View child) { |
| 1667 | return HeadsUpManager.isClickedHeadsUpNotification(child); |
| 1668 | } |
| 1669 | |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 1670 | /** |
| 1671 | * Remove a removed child view from the heads up animations if it was just added there |
| 1672 | * |
| 1673 | * @return whether any child was removed from the list to animate |
| 1674 | */ |
| 1675 | private boolean removeRemovedChildFromHeadsUpChangeAnimations(View child) { |
| 1676 | boolean hasAddEvent = false; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 1677 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
| 1678 | ExpandableNotificationRow row = eventPair.first; |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 1679 | boolean isHeadsUp = eventPair.second; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 1680 | if (child == row) { |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 1681 | mTmpList.add(eventPair); |
| 1682 | hasAddEvent |= isHeadsUp; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
Selim Cinek | e0890e5 | 2015-06-17 11:17:08 -0700 | [diff] [blame] | 1685 | if (hasAddEvent) { |
| 1686 | // This child was just added lets remove all events. |
| 1687 | mHeadsUpChangeAnimations.removeAll(mTmpList); |
| 1688 | } |
| 1689 | mTmpList.clear(); |
| 1690 | return hasAddEvent; |
Selim Cinek | ffa6eb8 | 2015-05-21 12:11:12 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1693 | /** |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1694 | * @param child the child to query |
| 1695 | * @return whether a view is not a top level child but a child notification and that group is |
| 1696 | * not expanded |
| 1697 | */ |
| 1698 | private boolean isChildInInvisibleGroup(View child) { |
| 1699 | if (child instanceof ExpandableNotificationRow) { |
| 1700 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 1701 | ExpandableNotificationRow groupSummary = |
| 1702 | mGroupManager.getGroupSummary(row.getStatusBarNotification()); |
| 1703 | if (groupSummary != null && groupSummary != row) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1704 | return row.getVisibility() == View.INVISIBLE; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1705 | } |
| 1706 | } |
| 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | /** |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1711 | * Updates the scroll position when a child was removed |
| 1712 | * |
| 1713 | * @param removedChild the removed child |
| 1714 | */ |
| 1715 | private void updateScrollStateForRemovedChild(View removedChild) { |
| 1716 | int startingPosition = getPositionInLinearLayout(removedChild); |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 1717 | int childHeight = getIntrinsicHeight(removedChild) + mPaddingBetweenElements; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1718 | int endPosition = startingPosition + childHeight; |
| 1719 | if (endPosition <= mOwnScrollY) { |
| 1720 | // This child is fully scrolled of the top, so we have to deduct its height from the |
| 1721 | // scrollPosition |
| 1722 | mOwnScrollY -= childHeight; |
| 1723 | } else if (startingPosition < mOwnScrollY) { |
| 1724 | // This child is currently being scrolled into, set the scroll position to the start of |
| 1725 | // this child |
| 1726 | mOwnScrollY = startingPosition; |
| 1727 | } |
| 1728 | } |
| 1729 | |
Selim Cinek | d7c4e00 | 2014-07-04 18:36:42 +0200 | [diff] [blame] | 1730 | private int getIntrinsicHeight(View view) { |
| 1731 | if (view instanceof ExpandableView) { |
| 1732 | ExpandableView expandableView = (ExpandableView) view; |
| 1733 | return expandableView.getIntrinsicHeight(); |
| 1734 | } |
| 1735 | return view.getHeight(); |
| 1736 | } |
| 1737 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1738 | private int getPositionInLinearLayout(View requestedChild) { |
| 1739 | int position = 0; |
| 1740 | for (int i = 0; i < getChildCount(); i++) { |
| 1741 | View child = getChildAt(i); |
| 1742 | if (child == requestedChild) { |
| 1743 | return position; |
| 1744 | } |
| 1745 | if (child.getVisibility() != View.GONE) { |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 1746 | position += getIntrinsicHeight(child); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1747 | if (i < getChildCount()-1) { |
| 1748 | position += mPaddingBetweenElements; |
| 1749 | } |
| 1750 | } |
| 1751 | } |
| 1752 | return 0; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | @Override |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 1756 | public void onViewAdded(View child) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1757 | super.onViewAdded(child); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1758 | onViewAddedInternal(child); |
| 1759 | } |
| 1760 | |
| 1761 | private void onViewAddedInternal(View child) { |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 1762 | updateHideSensitiveForChild(child); |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1763 | mStackScrollAlgorithm.notifyChildrenChanged(this); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1764 | ((ExpandableView) child).setOnHeightChangedListener(this); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1765 | generateAddAnimation(child, false /* fromMoreCard */); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 1766 | updateAnimationState(child); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 1767 | updateChronometerForChild(child); |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 1768 | if (canChildBeDismissed(child)) { |
| 1769 | // Make sure the dismissButton is visible and not in the animated state. |
| 1770 | // We need to do this to avoid a race where a clearable notification is added after the |
| 1771 | // dismiss animation is finished |
| 1772 | mDismissView.showClearButton(); |
| 1773 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
Selim Cinek | d06c41c | 2015-07-06 14:51:36 -0700 | [diff] [blame] | 1776 | private void updateHideSensitiveForChild(View child) { |
| 1777 | if (mAmbientState.isHideSensitive() && child instanceof ExpandableView) { |
| 1778 | ExpandableView expandableView = (ExpandableView) child; |
| 1779 | expandableView.setHideSensitiveForIntrinsicHeight(true); |
| 1780 | } |
| 1781 | } |
| 1782 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1783 | public void notifyGroupChildRemoved(View row) { |
| 1784 | onViewRemovedInternal(row); |
| 1785 | } |
| 1786 | |
| 1787 | public void notifyGroupChildAdded(View row) { |
| 1788 | onViewAddedInternal(row); |
| 1789 | } |
| 1790 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1791 | public void setAnimationsEnabled(boolean animationsEnabled) { |
| 1792 | mAnimationsEnabled = animationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1793 | updateNotificationAnimationStates(); |
| 1794 | } |
| 1795 | |
| 1796 | private void updateNotificationAnimationStates() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1797 | boolean running = mAnimationsEnabled; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1798 | int childCount = getChildCount(); |
| 1799 | for (int i = 0; i < childCount; i++) { |
| 1800 | View child = getChildAt(i); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1801 | running &= mIsExpanded || isPinnedHeadsUp(child); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1802 | updateAnimationState(running, child); |
| 1803 | } |
| 1804 | } |
| 1805 | |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 1806 | private void updateAnimationState(View child) { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1807 | updateAnimationState((mAnimationsEnabled || isPinnedHeadsUp(child)) && mIsExpanded, child); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1811 | private void updateAnimationState(boolean running, View child) { |
| 1812 | if (child instanceof ExpandableNotificationRow) { |
| 1813 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 1814 | row.setIconAnimationRunning(running); |
| 1815 | } |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | public boolean isAddOrRemoveAnimationPending() { |
| 1819 | return mNeedsAnimation |
| 1820 | && (!mChildrenToAddAnimated.isEmpty() || !mChildrenToRemoveAnimated.isEmpty()); |
| 1821 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1822 | /** |
| 1823 | * Generate an animation for an added child view. |
| 1824 | * |
| 1825 | * @param child The view to be added. |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1826 | * @param fromMoreCard Whether this add is coming from the "more" card on lockscreen. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1827 | */ |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1828 | public void generateAddAnimation(View child, boolean fromMoreCard) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1829 | if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1830 | // Generate Animations |
| 1831 | mChildrenToAddAnimated.add(child); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1832 | if (fromMoreCard) { |
| 1833 | mFromMoreCardAdditions.add(child); |
| 1834 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1835 | mNeedsAnimation = true; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1836 | } |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 1837 | if (isHeadsUp(child) && !mChangePositionInProgress) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1838 | mAddedHeadsUpChildren.add(child); |
| 1839 | mChildrenToAddAnimated.remove(child); |
| 1840 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * Change the position of child to a new location |
| 1845 | * |
| 1846 | * @param child the view to change the position for |
| 1847 | * @param newIndex the new index |
| 1848 | */ |
| 1849 | public void changeViewPosition(View child, int newIndex) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1850 | int currentIndex = indexOfChild(child); |
| 1851 | if (child != null && child.getParent() == this && currentIndex != newIndex) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1852 | mChangePositionInProgress = true; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 1853 | removeView(child); |
| 1854 | addView(child, newIndex); |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1855 | mChangePositionInProgress = false; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 1856 | if (mIsExpanded && mAnimationsEnabled && child.getVisibility() != View.GONE) { |
Selim Cinek | 159ffdb | 2014-06-04 22:24:18 +0200 | [diff] [blame] | 1857 | mChildrenChangingPositions.add(child); |
| 1858 | mNeedsAnimation = true; |
| 1859 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1860 | } |
| 1861 | } |
| 1862 | |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1863 | private void startAnimationToState() { |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1864 | if (mNeedsAnimation) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1865 | generateChildHierarchyEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1866 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1867 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1868 | if (!mAnimationEvents.isEmpty() || isCurrentlyAnimating()) { |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 1869 | mStateAnimator.startAnimationForEvents(mAnimationEvents, mCurrentStackScrollState, |
| 1870 | mGoToFullShadeDelay); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1871 | mAnimationEvents.clear(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 1872 | } else { |
| 1873 | applyCurrentState(); |
| 1874 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 1875 | mGoToFullShadeDelay = 0; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | private void generateChildHierarchyEvents() { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1879 | generateHeadsUpAnimationEvents(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1880 | generateChildRemovalEvents(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1881 | generateChildAdditionEvents(); |
| 1882 | generatePositionChangeEvents(); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1883 | generateSnapBackEvents(); |
| 1884 | generateDragEvents(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1885 | generateTopPaddingEvent(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1886 | generateActivateEvent(); |
| 1887 | generateDimmedEvent(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1888 | generateHideSensitiveEvent(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 1889 | generateDarkEvent(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 1890 | generateGoToFullShadeEvent(); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1891 | generateViewResizeEvent(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1892 | generateGroupExpansionEvent(); |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 1893 | generateAnimateEverythingEvent(); |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1894 | mNeedsAnimation = false; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1895 | } |
| 1896 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1897 | private void generateHeadsUpAnimationEvents() { |
| 1898 | for (Pair<ExpandableNotificationRow, Boolean> eventPair : mHeadsUpChangeAnimations) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1899 | ExpandableNotificationRow row = eventPair.first; |
| 1900 | boolean isHeadsUp = eventPair.second; |
| 1901 | int type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_OTHER; |
| 1902 | boolean onBottom = false; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 1903 | boolean pinnedAndClosed = row.isPinned() && !mIsExpanded; |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 1904 | if (!mIsExpanded && !isHeadsUp) { |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 1905 | type = row.wasJustClicked() |
| 1906 | ? AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 1907 | : AnimationEvent.ANIMATION_TYPE_HEADS_UP_DISAPPEAR; |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 1908 | } else { |
| 1909 | StackViewState viewState = mCurrentStackScrollState.getViewStateForView(row); |
| 1910 | if (viewState == null) { |
| 1911 | // A view state was never generated for this view, so we don't need to animate |
| 1912 | // this. This may happen with notification children. |
| 1913 | continue; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1914 | } |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 1915 | if (isHeadsUp && (mAddedHeadsUpChildren.contains(row) || pinnedAndClosed)) { |
| 1916 | if (pinnedAndClosed || shouldHunAppearFromBottom(viewState)) { |
| 1917 | // Our custom add animation |
| 1918 | type = AnimationEvent.ANIMATION_TYPE_HEADS_UP_APPEAR; |
| 1919 | } else { |
| 1920 | // Normal add animation |
| 1921 | type = AnimationEvent.ANIMATION_TYPE_ADD; |
| 1922 | } |
| 1923 | onBottom = !pinnedAndClosed; |
| 1924 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1925 | } |
| 1926 | AnimationEvent event = new AnimationEvent(row, type); |
| 1927 | event.headsUpFromBottom = onBottom; |
| 1928 | mAnimationEvents.add(event); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1929 | } |
| 1930 | mHeadsUpChangeAnimations.clear(); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1931 | mAddedHeadsUpChildren.clear(); |
| 1932 | } |
| 1933 | |
Selim Cinek | eaee9c0 | 2015-06-25 11:04:20 -0400 | [diff] [blame] | 1934 | private boolean shouldHunAppearFromBottom(StackViewState viewState) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1935 | if (viewState.yTranslation + viewState.height < mAmbientState.getMaxHeadsUpTranslation()) { |
| 1936 | return false; |
| 1937 | } |
| 1938 | return true; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1941 | private void generateGroupExpansionEvent() { |
| 1942 | // Generate a group expansion/collapsing event if there is such a group at all |
| 1943 | if (mExpandedGroupView != null) { |
| 1944 | mAnimationEvents.add(new AnimationEvent(mExpandedGroupView, |
| 1945 | AnimationEvent.ANIMATION_TYPE_GROUP_EXPANSION_CHANGED)); |
| 1946 | mExpandedGroupView = null; |
| 1947 | } |
| 1948 | } |
| 1949 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 1950 | private void generateViewResizeEvent() { |
| 1951 | if (mNeedViewResizeAnimation) { |
| 1952 | mAnimationEvents.add( |
| 1953 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_VIEW_RESIZE)); |
| 1954 | } |
| 1955 | mNeedViewResizeAnimation = false; |
| 1956 | } |
| 1957 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1958 | private void generateSnapBackEvents() { |
| 1959 | for (View child : mSnappedBackChildren) { |
| 1960 | mAnimationEvents.add(new AnimationEvent(child, |
| 1961 | AnimationEvent.ANIMATION_TYPE_SNAP_BACK)); |
| 1962 | } |
| 1963 | mSnappedBackChildren.clear(); |
| 1964 | } |
| 1965 | |
| 1966 | private void generateDragEvents() { |
| 1967 | for (View child : mDragAnimPendingChildren) { |
| 1968 | mAnimationEvents.add(new AnimationEvent(child, |
| 1969 | AnimationEvent.ANIMATION_TYPE_START_DRAG)); |
| 1970 | } |
| 1971 | mDragAnimPendingChildren.clear(); |
| 1972 | } |
| 1973 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1974 | private void generateChildRemovalEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 1975 | for (View child : mChildrenToRemoveAnimated) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1976 | boolean childWasSwipedOut = mSwipedOutViews.contains(child); |
| 1977 | int animationType = childWasSwipedOut |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 1978 | ? AnimationEvent.ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 1979 | : AnimationEvent.ANIMATION_TYPE_REMOVE; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1980 | AnimationEvent event = new AnimationEvent(child, animationType); |
| 1981 | |
| 1982 | // we need to know the view after this one |
| 1983 | event.viewAfterChangingView = getFirstChildBelowTranlsationY(child.getTranslationY()); |
| 1984 | mAnimationEvents.add(event); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 1985 | } |
| 1986 | mSwipedOutViews.clear(); |
| 1987 | mChildrenToRemoveAnimated.clear(); |
| 1988 | } |
| 1989 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1990 | private void generatePositionChangeEvents() { |
| 1991 | for (View child : mChildrenChangingPositions) { |
| 1992 | mAnimationEvents.add(new AnimationEvent(child, |
| 1993 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 1994 | } |
| 1995 | mChildrenChangingPositions.clear(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1996 | if (mGenerateChildOrderChangedEvent) { |
| 1997 | mAnimationEvents.add(new AnimationEvent(null, |
| 1998 | AnimationEvent.ANIMATION_TYPE_CHANGE_POSITION)); |
| 1999 | mGenerateChildOrderChangedEvent = false; |
| 2000 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2003 | private void generateChildAdditionEvents() { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 2004 | for (View child : mChildrenToAddAnimated) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2005 | if (mFromMoreCardAdditions.contains(child)) { |
| 2006 | mAnimationEvents.add(new AnimationEvent(child, |
| 2007 | AnimationEvent.ANIMATION_TYPE_ADD, |
| 2008 | StackStateAnimator.ANIMATION_DURATION_STANDARD)); |
| 2009 | } else { |
| 2010 | mAnimationEvents.add(new AnimationEvent(child, |
| 2011 | AnimationEvent.ANIMATION_TYPE_ADD)); |
| 2012 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2013 | } |
| 2014 | mChildrenToAddAnimated.clear(); |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 2015 | mFromMoreCardAdditions.clear(); |
Christoph Studer | 068f592 | 2014-04-08 17:43:07 -0400 | [diff] [blame] | 2016 | } |
| 2017 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2018 | private void generateTopPaddingEvent() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 2019 | if (mTopPaddingNeedsAnimation) { |
| 2020 | mAnimationEvents.add( |
| 2021 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_TOP_PADDING_CHANGED)); |
| 2022 | } |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2023 | mTopPaddingNeedsAnimation = false; |
| 2024 | } |
| 2025 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2026 | private void generateActivateEvent() { |
| 2027 | if (mActivateNeedsAnimation) { |
| 2028 | mAnimationEvents.add( |
| 2029 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_ACTIVATED_CHILD)); |
| 2030 | } |
| 2031 | mActivateNeedsAnimation = false; |
| 2032 | } |
| 2033 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2034 | private void generateAnimateEverythingEvent() { |
| 2035 | if (mEverythingNeedsAnimation) { |
| 2036 | mAnimationEvents.add( |
| 2037 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_EVERYTHING)); |
| 2038 | } |
| 2039 | mEverythingNeedsAnimation = false; |
| 2040 | } |
| 2041 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2042 | private void generateDimmedEvent() { |
| 2043 | if (mDimmedNeedsAnimation) { |
| 2044 | mAnimationEvents.add( |
| 2045 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DIMMED)); |
| 2046 | } |
| 2047 | mDimmedNeedsAnimation = false; |
| 2048 | } |
| 2049 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2050 | private void generateHideSensitiveEvent() { |
| 2051 | if (mHideSensitiveNeedsAnimation) { |
| 2052 | mAnimationEvents.add( |
| 2053 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_HIDE_SENSITIVE)); |
| 2054 | } |
| 2055 | mHideSensitiveNeedsAnimation = false; |
| 2056 | } |
| 2057 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2058 | private void generateDarkEvent() { |
| 2059 | if (mDarkNeedsAnimation) { |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2060 | AnimationEvent ev = new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_DARK); |
| 2061 | ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex; |
| 2062 | mAnimationEvents.add(ev); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2063 | } |
| 2064 | mDarkNeedsAnimation = false; |
| 2065 | } |
| 2066 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2067 | private void generateGoToFullShadeEvent() { |
| 2068 | if (mGoToFullShadeNeedsAnimation) { |
| 2069 | mAnimationEvents.add( |
| 2070 | new AnimationEvent(null, AnimationEvent.ANIMATION_TYPE_GO_TO_FULL_SHADE)); |
| 2071 | } |
| 2072 | mGoToFullShadeNeedsAnimation = false; |
| 2073 | } |
| 2074 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2075 | private boolean onInterceptTouchEventScroll(MotionEvent ev) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2076 | if (!isScrollingEnabled()) { |
| 2077 | return false; |
| 2078 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2079 | /* |
| 2080 | * This method JUST determines whether we want to intercept the motion. |
| 2081 | * If we return true, onMotionEvent will be called and we do the actual |
| 2082 | * scrolling there. |
| 2083 | */ |
| 2084 | |
| 2085 | /* |
| 2086 | * Shortcut the most recurring case: the user is in the dragging |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 2087 | * state and is moving their finger. We want to intercept this |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2088 | * motion. |
| 2089 | */ |
| 2090 | final int action = ev.getAction(); |
| 2091 | if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { |
| 2092 | return true; |
| 2093 | } |
| 2094 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2095 | switch (action & MotionEvent.ACTION_MASK) { |
| 2096 | case MotionEvent.ACTION_MOVE: { |
| 2097 | /* |
| 2098 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
Chris Wren | 5d53df4 | 2015-06-26 11:26:03 -0400 | [diff] [blame] | 2099 | * whether the user has moved far enough from the original down touch. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2100 | */ |
| 2101 | |
| 2102 | /* |
| 2103 | * Locally do absolute value. mLastMotionY is set to the y value |
| 2104 | * of the down event. |
| 2105 | */ |
| 2106 | final int activePointerId = mActivePointerId; |
| 2107 | if (activePointerId == INVALID_POINTER) { |
| 2108 | // If we don't have a valid id, the touch down wasn't on content. |
| 2109 | break; |
| 2110 | } |
| 2111 | |
| 2112 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 2113 | if (pointerIndex == -1) { |
| 2114 | Log.e(TAG, "Invalid pointerId=" + activePointerId |
| 2115 | + " in onInterceptTouchEvent"); |
| 2116 | break; |
| 2117 | } |
| 2118 | |
| 2119 | final int y = (int) ev.getY(pointerIndex); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2120 | final int x = (int) ev.getX(pointerIndex); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2121 | final int yDiff = Math.abs(y - mLastMotionY); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2122 | final int xDiff = Math.abs(x - mDownX); |
| 2123 | if (yDiff > mTouchSlop && yDiff > xDiff) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2124 | setIsBeingDragged(true); |
| 2125 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2126 | mDownX = x; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2127 | initVelocityTrackerIfNotExists(); |
| 2128 | mVelocityTracker.addMovement(ev); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2129 | } |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | case MotionEvent.ACTION_DOWN: { |
| 2134 | final int y = (int) ev.getY(); |
Jayasri bhattacharyya | 5e55c89 | 2015-09-10 16:00:10 +0530 | [diff] [blame] | 2135 | mScrolledToTopOnFirstDown = isScrolledToTop(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2136 | if (getChildAtPosition(ev.getX(), y) == null) { |
| 2137 | setIsBeingDragged(false); |
| 2138 | recycleVelocityTracker(); |
| 2139 | break; |
| 2140 | } |
| 2141 | |
| 2142 | /* |
| 2143 | * Remember location of down touch. |
| 2144 | * ACTION_DOWN always refers to pointer index 0. |
| 2145 | */ |
| 2146 | mLastMotionY = y; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2147 | mDownX = (int) ev.getX(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2148 | mActivePointerId = ev.getPointerId(0); |
| 2149 | |
| 2150 | initOrResetVelocityTracker(); |
| 2151 | mVelocityTracker.addMovement(ev); |
| 2152 | /* |
| 2153 | * If being flinged and user touches the screen, initiate drag; |
| 2154 | * otherwise don't. mScroller.isFinished should be false when |
| 2155 | * being flinged. |
| 2156 | */ |
| 2157 | boolean isBeingDragged = !mScroller.isFinished(); |
| 2158 | setIsBeingDragged(isBeingDragged); |
| 2159 | break; |
| 2160 | } |
| 2161 | |
| 2162 | case MotionEvent.ACTION_CANCEL: |
| 2163 | case MotionEvent.ACTION_UP: |
| 2164 | /* Release the drag */ |
| 2165 | setIsBeingDragged(false); |
| 2166 | mActivePointerId = INVALID_POINTER; |
| 2167 | recycleVelocityTracker(); |
| 2168 | if (mScroller.springBack(mScrollX, mOwnScrollY, 0, 0, 0, getScrollRange())) { |
| 2169 | postInvalidateOnAnimation(); |
| 2170 | } |
| 2171 | break; |
| 2172 | case MotionEvent.ACTION_POINTER_UP: |
| 2173 | onSecondaryPointerUp(ev); |
| 2174 | break; |
| 2175 | } |
| 2176 | |
| 2177 | /* |
| 2178 | * The only time we want to intercept motion events is if we are in the |
| 2179 | * drag mode. |
| 2180 | */ |
| 2181 | return mIsBeingDragged; |
| 2182 | } |
| 2183 | |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 2184 | /** |
| 2185 | * @return Whether the specified motion event is actually happening over the content. |
| 2186 | */ |
| 2187 | private boolean isInContentBounds(MotionEvent event) { |
Selim Cinek | ab1dc95 | 2014-10-30 20:20:29 +0100 | [diff] [blame] | 2188 | return isInContentBounds(event.getY()); |
| 2189 | } |
| 2190 | |
| 2191 | /** |
| 2192 | * @return Whether a y coordinate is inside the content. |
| 2193 | */ |
| 2194 | public boolean isInContentBounds(float y) { |
| 2195 | return y < getHeight() - getEmptyBottomMargin(); |
Jorim Jaggi | fe6bfa6 | 2014-05-07 23:23:18 +0200 | [diff] [blame] | 2196 | } |
| 2197 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2198 | private void setIsBeingDragged(boolean isDragged) { |
| 2199 | mIsBeingDragged = isDragged; |
| 2200 | if (isDragged) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2201 | requestDisallowInterceptTouchEvent(true); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2202 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | @Override |
| 2207 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 2208 | super.onWindowFocusChanged(hasWindowFocus); |
| 2209 | if (!hasWindowFocus) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2210 | removeLongPressCallback(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 2211 | } |
| 2212 | } |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2213 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2214 | public void removeLongPressCallback() { |
| 2215 | mSwipeHelper.removeLongPressCallback(); |
| 2216 | } |
| 2217 | |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2218 | @Override |
| 2219 | public boolean isScrolledToTop() { |
| 2220 | return mOwnScrollY == 0; |
| 2221 | } |
| 2222 | |
| 2223 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2224 | public boolean isScrolledToBottom() { |
| 2225 | return mOwnScrollY >= getScrollRange(); |
| 2226 | } |
| 2227 | |
| 2228 | @Override |
Selim Cinek | fab078b | 2014-03-27 22:45:58 +0100 | [diff] [blame] | 2229 | public View getHostView() { |
| 2230 | return this; |
| 2231 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2232 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2233 | public int getEmptyBottomMargin() { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2234 | int emptyMargin = mMaxLayoutHeight - mContentHeight - mBottomStackPeekSize; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2235 | if (needsHeightAdaption()) { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2236 | emptyMargin -= mBottomStackSlowDownHeight; |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 2237 | } else { |
Jorim Jaggi | 2c5baca | 2014-07-11 01:30:10 +0200 | [diff] [blame] | 2238 | emptyMargin -= mCollapseSecondCardPadding; |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 2239 | } |
| 2240 | return Math.max(emptyMargin, 0); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 2243 | public float getKeyguardBottomStackSize() { |
| 2244 | return mBottomStackPeekSize + getResources().getDimensionPixelSize( |
| 2245 | R.dimen.bottom_stack_slow_down_length); |
| 2246 | } |
| 2247 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2248 | public void onExpansionStarted() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2249 | mIsExpansionChanging = true; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2250 | mStackScrollAlgorithm.onExpansionStarted(mCurrentStackScrollState); |
| 2251 | } |
| 2252 | |
| 2253 | public void onExpansionStopped() { |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2254 | mIsExpansionChanging = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2255 | mStackScrollAlgorithm.onExpansionStopped(); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 2256 | if (!mIsExpanded) { |
| 2257 | mOwnScrollY = 0; |
Selim Cinek | f336f4c | 2014-11-12 16:58:16 +0100 | [diff] [blame] | 2258 | |
| 2259 | // lets make sure nothing is in the overlay anymore |
| 2260 | getOverlay().clear(); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 2261 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2262 | } |
| 2263 | |
Jorim Jaggi | e4b840d | 2015-06-30 16:19:17 -0700 | [diff] [blame] | 2264 | public void onPanelTrackingStarted() { |
| 2265 | mPanelTracking = true; |
| 2266 | } |
| 2267 | public void onPanelTrackingStopped() { |
| 2268 | mPanelTracking = false; |
| 2269 | } |
| 2270 | |
Selim Cinek | b24e0a9 | 2015-06-09 20:17:30 -0700 | [diff] [blame] | 2271 | public void resetScrollPosition() { |
| 2272 | mScroller.abortAnimation(); |
| 2273 | mOwnScrollY = 0; |
| 2274 | } |
| 2275 | |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 2276 | private void setIsExpanded(boolean isExpanded) { |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2277 | boolean changed = isExpanded != mIsExpanded; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2278 | mIsExpanded = isExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2279 | mStackScrollAlgorithm.setIsExpanded(isExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2280 | if (changed) { |
| 2281 | updateNotificationAnimationStates(); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 2282 | updateChronometers(); |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | private void updateChronometers() { |
| 2287 | int childCount = getChildCount(); |
| 2288 | for (int i = 0; i < childCount; i++) { |
| 2289 | updateChronometerForChild(getChildAt(i)); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | private void updateChronometerForChild(View child) { |
| 2294 | if (child instanceof ExpandableNotificationRow) { |
| 2295 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2296 | row.setChronometerRunning(mIsExpanded); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 2297 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2300 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2301 | public void onHeightChanged(ExpandableView view, boolean needsAnimation) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2302 | updateContentHeight(); |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2303 | updateScrollPositionOnExpandInBottom(view); |
| 2304 | clampScrollPosition(); |
Selim Cinek | aef92ef | 2014-06-06 18:06:04 +0200 | [diff] [blame] | 2305 | notifyHeightChangeListener(view); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2306 | if (needsAnimation) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 2307 | ExpandableNotificationRow row = view instanceof ExpandableNotificationRow |
| 2308 | ? (ExpandableNotificationRow) view |
| 2309 | : null; |
| 2310 | requestAnimationOnViewResize(row); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2311 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2312 | requestChildrenUpdate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2313 | } |
| 2314 | |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2315 | @Override |
| 2316 | public void onReset(ExpandableView view) { |
Selim Cinek | 0e41dea | 2014-08-25 13:55:06 +0200 | [diff] [blame] | 2317 | if (mIsExpanded && mAnimationsEnabled) { |
| 2318 | mRequestViewResizeAnimationOnLayout = true; |
| 2319 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2320 | mStackScrollAlgorithm.onReset(view); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2321 | updateAnimationState(view); |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 2322 | updateChronometerForChild(view); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2323 | } |
| 2324 | |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2325 | private void updateScrollPositionOnExpandInBottom(ExpandableView view) { |
| 2326 | if (view instanceof ExpandableNotificationRow) { |
| 2327 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2328 | if (row.isUserLocked() && row != getFirstChildNotGone()) { |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2329 | // We are actually expanding this view |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 2330 | float endPosition; |
| 2331 | if (row.isChildInGroup()) { |
| 2332 | ExpandableNotificationRow parent = row.getNotificationParent(); |
| 2333 | endPosition = parent.getTranslationY() + parent.getActualHeight(); |
| 2334 | } else { |
| 2335 | endPosition = row.getTranslationY() + row.getActualHeight(); |
| 2336 | } |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2337 | int stackEnd = mMaxLayoutHeight - mBottomStackPeekSize - |
Selim Cinek | cb9400a | 2015-06-03 16:56:13 +0200 | [diff] [blame] | 2338 | mBottomStackSlowDownHeight + (int) mStackTranslation; |
Selim Cinek | f7a14c0 | 2014-07-07 14:01:46 +0200 | [diff] [blame] | 2339 | if (endPosition > stackEnd) { |
| 2340 | mOwnScrollY += endPosition - stackEnd; |
| 2341 | mDisallowScrollingInThisMotion = true; |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2347 | public void setOnHeightChangedListener( |
| 2348 | ExpandableView.OnHeightChangedListener mOnHeightChangedListener) { |
| 2349 | this.mOnHeightChangedListener = mOnHeightChangedListener; |
| 2350 | } |
| 2351 | |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2352 | public void setOnEmptySpaceClickListener(OnEmptySpaceClickListener listener) { |
| 2353 | mOnEmptySpaceClickListener = listener; |
| 2354 | } |
| 2355 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2356 | public void onChildAnimationFinished() { |
Selim Cinek | 319bdc4 | 2014-05-01 23:01:58 +0200 | [diff] [blame] | 2357 | requestChildrenUpdate(); |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2358 | runAnimationFinishedRunnables(); |
Selim Cinek | 0fccc72 | 2015-07-29 17:04:36 -0700 | [diff] [blame] | 2359 | clearViewOverlays(); |
| 2360 | } |
| 2361 | |
| 2362 | private void clearViewOverlays() { |
| 2363 | for (View view : mClearOverlayViewsWhenFinished) { |
| 2364 | getOverlay().remove(view); |
| 2365 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | private void runAnimationFinishedRunnables() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2369 | for (Runnable runnable : mAnimationFinishedRunnables) { |
| 2370 | runnable.run(); |
| 2371 | } |
| 2372 | mAnimationFinishedRunnables.clear(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2373 | } |
| 2374 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2375 | /** |
| 2376 | * See {@link AmbientState#setDimmed}. |
| 2377 | */ |
| 2378 | public void setDimmed(boolean dimmed, boolean animate) { |
| 2379 | mAmbientState.setDimmed(dimmed); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2380 | if (animate && mAnimationsEnabled) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2381 | mDimmedNeedsAnimation = true; |
| 2382 | mNeedsAnimation = true; |
| 2383 | } |
| 2384 | requestChildrenUpdate(); |
| 2385 | } |
| 2386 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2387 | public void setHideSensitive(boolean hideSensitive, boolean animate) { |
| 2388 | if (hideSensitive != mAmbientState.isHideSensitive()) { |
| 2389 | int childCount = getChildCount(); |
| 2390 | for (int i = 0; i < childCount; i++) { |
| 2391 | ExpandableView v = (ExpandableView) getChildAt(i); |
| 2392 | v.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 2393 | } |
| 2394 | mAmbientState.setHideSensitive(hideSensitive); |
| 2395 | if (animate && mAnimationsEnabled) { |
| 2396 | mHideSensitiveNeedsAnimation = true; |
| 2397 | mNeedsAnimation = true; |
| 2398 | } |
| 2399 | requestChildrenUpdate(); |
| 2400 | } |
| 2401 | } |
| 2402 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2403 | /** |
| 2404 | * See {@link AmbientState#setActivatedChild}. |
| 2405 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 2406 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2407 | mAmbientState.setActivatedChild(activatedChild); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 2408 | if (mAnimationsEnabled) { |
| 2409 | mActivateNeedsAnimation = true; |
| 2410 | mNeedsAnimation = true; |
| 2411 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2412 | requestChildrenUpdate(); |
| 2413 | } |
| 2414 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 2415 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2416 | return mAmbientState.getActivatedChild(); |
| 2417 | } |
| 2418 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2419 | private void applyCurrentState() { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2420 | mCurrentStackScrollState.apply(); |
Selim Cinek | f4c1996 | 2014-05-01 21:55:31 +0200 | [diff] [blame] | 2421 | if (mListener != null) { |
| 2422 | mListener.onChildLocationsChanged(this); |
| 2423 | } |
Selim Cinek | 32a59fd3 | 2015-06-10 13:54:42 -0700 | [diff] [blame] | 2424 | runAnimationFinishedRunnables(); |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2425 | } |
| 2426 | |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2427 | public void goToFullShade(long delay) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2428 | mDismissView.setInvisible(); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2429 | mEmptyShadeView.setInvisible(); |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2430 | mGoToFullShadeNeedsAnimation = true; |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2431 | mGoToFullShadeDelay = delay; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2432 | mNeedsAnimation = true; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2433 | requestChildrenUpdate(); |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 2434 | } |
| 2435 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2436 | public void cancelExpandHelper() { |
| 2437 | mExpandHelper.cancel(); |
| 2438 | } |
| 2439 | |
| 2440 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 2441 | mIntrinsicPadding = intrinsicPadding; |
| 2442 | } |
| 2443 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 2444 | public int getIntrinsicPadding() { |
| 2445 | return mIntrinsicPadding; |
| 2446 | } |
| 2447 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2448 | /** |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2449 | * @return the y position of the first notification |
| 2450 | */ |
| 2451 | public float getNotificationsTopY() { |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 2452 | return mTopPadding + getStackTranslation(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2453 | } |
| 2454 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 2455 | @Override |
| 2456 | public boolean shouldDelayChildPressedState() { |
| 2457 | return true; |
| 2458 | } |
| 2459 | |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 2460 | /** |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2461 | * See {@link AmbientState#setDark}. |
| 2462 | */ |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2463 | public void setDark(boolean dark, boolean animate, @Nullable PointF touchWakeUpScreenLocation) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2464 | mAmbientState.setDark(dark); |
| 2465 | if (animate && mAnimationsEnabled) { |
| 2466 | mDarkNeedsAnimation = true; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2467 | mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2468 | mNeedsAnimation = true; |
| 2469 | } |
| 2470 | requestChildrenUpdate(); |
| 2471 | } |
| 2472 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 2473 | private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) { |
| 2474 | if (screenLocation == null || screenLocation.y < mTopPadding + mTopPaddingOverflow) { |
| 2475 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 2476 | } |
| 2477 | if (screenLocation.y > getBottomMostNotificationBottom()) { |
| 2478 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_BELOW; |
| 2479 | } |
| 2480 | View child = getClosestChildAtRawPosition(screenLocation.x, screenLocation.y); |
| 2481 | if (child != null) { |
| 2482 | return getNotGoneIndex(child); |
| 2483 | } else { |
| 2484 | return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE; |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | private int getNotGoneIndex(View child) { |
| 2489 | int count = getChildCount(); |
| 2490 | int notGoneIndex = 0; |
| 2491 | for (int i = 0; i < count; i++) { |
| 2492 | View v = getChildAt(i); |
| 2493 | if (child == v) { |
| 2494 | return notGoneIndex; |
| 2495 | } |
| 2496 | if (v.getVisibility() != View.GONE) { |
| 2497 | notGoneIndex++; |
| 2498 | } |
| 2499 | } |
| 2500 | return -1; |
| 2501 | } |
| 2502 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2503 | public void setDismissView(DismissView dismissView) { |
| 2504 | mDismissView = dismissView; |
| 2505 | addView(mDismissView); |
| 2506 | } |
| 2507 | |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2508 | public void setEmptyShadeView(EmptyShadeView emptyShadeView) { |
| 2509 | mEmptyShadeView = emptyShadeView; |
| 2510 | addView(mEmptyShadeView); |
| 2511 | } |
| 2512 | |
| 2513 | public void updateEmptyShadeView(boolean visible) { |
| 2514 | int oldVisibility = mEmptyShadeView.willBeGone() ? GONE : mEmptyShadeView.getVisibility(); |
| 2515 | int newVisibility = visible ? VISIBLE : GONE; |
| 2516 | if (oldVisibility != newVisibility) { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2517 | if (newVisibility != GONE) { |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2518 | if (mEmptyShadeView.willBeGone()) { |
| 2519 | mEmptyShadeView.cancelAnimation(); |
| 2520 | } else { |
| 2521 | mEmptyShadeView.setInvisible(); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2522 | } |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2523 | mEmptyShadeView.setVisibility(newVisibility); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2524 | mEmptyShadeView.setWillBeGone(false); |
| 2525 | updateContentHeight(); |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2526 | notifyHeightChangeListener(mEmptyShadeView); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2527 | } else { |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 2528 | Runnable onFinishedRunnable = new Runnable() { |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2529 | @Override |
| 2530 | public void run() { |
| 2531 | mEmptyShadeView.setVisibility(GONE); |
| 2532 | mEmptyShadeView.setWillBeGone(false); |
| 2533 | updateContentHeight(); |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2534 | notifyHeightChangeListener(mEmptyShadeView); |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2535 | } |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 2536 | }; |
| 2537 | if (mAnimationsEnabled) { |
| 2538 | mEmptyShadeView.setWillBeGone(true); |
| 2539 | mEmptyShadeView.performVisibilityAnimation(false, onFinishedRunnable); |
| 2540 | } else { |
| 2541 | mEmptyShadeView.setInvisible(); |
| 2542 | onFinishedRunnable.run(); |
| 2543 | } |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | } |
| 2547 | |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 2548 | public void setOverflowContainer(NotificationOverflowContainer overFlowContainer) { |
| 2549 | mOverflowContainer = overFlowContainer; |
| 2550 | addView(mOverflowContainer); |
| 2551 | } |
| 2552 | |
| 2553 | public void updateOverflowContainerVisibility(boolean visible) { |
| 2554 | int oldVisibility = mOverflowContainer.willBeGone() ? GONE |
| 2555 | : mOverflowContainer.getVisibility(); |
| 2556 | final int newVisibility = visible ? VISIBLE : GONE; |
| 2557 | if (oldVisibility != newVisibility) { |
| 2558 | Runnable onFinishedRunnable = new Runnable() { |
| 2559 | @Override |
| 2560 | public void run() { |
| 2561 | mOverflowContainer.setVisibility(newVisibility); |
| 2562 | mOverflowContainer.setWillBeGone(false); |
| 2563 | updateContentHeight(); |
| 2564 | notifyHeightChangeListener(mOverflowContainer); |
| 2565 | } |
| 2566 | }; |
| 2567 | if (!mAnimationsEnabled || !mIsExpanded) { |
| 2568 | mOverflowContainer.cancelAppearDrawing(); |
| 2569 | onFinishedRunnable.run(); |
| 2570 | } else if (newVisibility != GONE) { |
| 2571 | mOverflowContainer.performAddAnimation(0, |
| 2572 | StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 2573 | mOverflowContainer.setVisibility(newVisibility); |
| 2574 | mOverflowContainer.setWillBeGone(false); |
| 2575 | updateContentHeight(); |
| 2576 | notifyHeightChangeListener(mOverflowContainer); |
| 2577 | } else { |
| 2578 | mOverflowContainer.performRemoveAnimation( |
| 2579 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 2580 | 0.0f, |
| 2581 | onFinishedRunnable); |
| 2582 | mOverflowContainer.setWillBeGone(true); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2587 | public void updateDismissView(boolean visible) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2588 | int oldVisibility = mDismissView.willBeGone() ? GONE : mDismissView.getVisibility(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2589 | int newVisibility = visible ? VISIBLE : GONE; |
| 2590 | if (oldVisibility != newVisibility) { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2591 | if (newVisibility != GONE) { |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2592 | if (mDismissView.willBeGone()) { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2593 | mDismissView.cancelAnimation(); |
| 2594 | } else { |
| 2595 | mDismissView.setInvisible(); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2596 | } |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2597 | mDismissView.setVisibility(newVisibility); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2598 | mDismissView.setWillBeGone(false); |
| 2599 | updateContentHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2600 | notifyHeightChangeListener(mDismissView); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2601 | } else { |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 2602 | Runnable dimissHideFinishRunnable = new Runnable() { |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2603 | @Override |
| 2604 | public void run() { |
| 2605 | mDismissView.setVisibility(GONE); |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2606 | mDismissView.setWillBeGone(false); |
| 2607 | updateContentHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 2608 | notifyHeightChangeListener(mDismissView); |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2609 | } |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 2610 | }; |
Selim Cinek | 2086710 | 2014-12-10 17:09:17 +0100 | [diff] [blame] | 2611 | if (mDismissView.isButtonVisible() && mIsExpanded && mAnimationsEnabled) { |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 2612 | mDismissView.setWillBeGone(true); |
| 2613 | mDismissView.performVisibilityAnimation(false, dimissHideFinishRunnable); |
| 2614 | } else { |
| 2615 | dimissHideFinishRunnable.run(); |
| 2616 | mDismissView.showClearButton(); |
| 2617 | } |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 2623 | mDismissAllInProgress = dismissAllInProgress; |
Selim Cinek | 7d5f374 | 2014-11-07 18:07:49 +0100 | [diff] [blame] | 2624 | mDismissView.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 2625 | mAmbientState.setDismissAllInProgress(dismissAllInProgress); |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 2626 | if (dismissAllInProgress) { |
| 2627 | disableClipOptimization(); |
| 2628 | } |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 2629 | handleDismissAllClipping(); |
| 2630 | } |
| 2631 | |
| 2632 | private void handleDismissAllClipping() { |
| 2633 | final int count = getChildCount(); |
| 2634 | boolean previousChildWillBeDismissed = false; |
| 2635 | for (int i = 0; i < count; i++) { |
| 2636 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2637 | if (child.getVisibility() == GONE) { |
| 2638 | continue; |
| 2639 | } |
| 2640 | if (mDismissAllInProgress && previousChildWillBeDismissed) { |
| 2641 | child.setMinClipTopAmount(child.getClipTopAmount()); |
| 2642 | } else { |
| 2643 | child.setMinClipTopAmount(0); |
| 2644 | } |
| 2645 | previousChildWillBeDismissed = canChildBeDismissed(child); |
| 2646 | } |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | private void disableClipOptimization() { |
| 2650 | final int count = getChildCount(); |
| 2651 | for (int i = 0; i < count; i++) { |
| 2652 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2653 | if (child.getVisibility() == GONE) { |
| 2654 | continue; |
| 2655 | } |
| 2656 | child.setClipTopOptimization(0); |
| 2657 | } |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 2658 | } |
| 2659 | |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2660 | public boolean isDismissViewNotGone() { |
| 2661 | return mDismissView.getVisibility() != View.GONE && !mDismissView.willBeGone(); |
| 2662 | } |
| 2663 | |
| 2664 | public boolean isDismissViewVisible() { |
| 2665 | return mDismissView.isVisible(); |
| 2666 | } |
| 2667 | |
| 2668 | public int getDismissViewHeight() { |
Jorim Jaggi | 1d49ec9 | 2014-08-25 18:44:01 +0200 | [diff] [blame] | 2669 | int height = mDismissView.getHeight() + mPaddingBetweenElementsNormal; |
| 2670 | |
| 2671 | // Hack: Accommodate for additional distance when we only have one notification and the |
| 2672 | // dismiss all button. |
| 2673 | if (getNotGoneChildCount() == 2 && getLastChildNotGone() == mDismissView |
| 2674 | && getFirstChildNotGone() instanceof ActivatableNotificationView) { |
| 2675 | height += mCollapseSecondCardPadding; |
| 2676 | } |
| 2677 | return height; |
Jorim Jaggi | 4b04a3a | 2014-07-28 17:43:56 +0200 | [diff] [blame] | 2678 | } |
| 2679 | |
Jorim Jaggi | 0cce70c | 2014-11-04 16:13:41 +0100 | [diff] [blame] | 2680 | public int getEmptyShadeViewHeight() { |
| 2681 | return mEmptyShadeView.getHeight(); |
| 2682 | } |
| 2683 | |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 2684 | public float getBottomMostNotificationBottom() { |
| 2685 | final int count = getChildCount(); |
| 2686 | float max = 0; |
| 2687 | for (int childIdx = 0; childIdx < count; childIdx++) { |
| 2688 | ExpandableView child = (ExpandableView) getChildAt(childIdx); |
| 2689 | if (child.getVisibility() == GONE) { |
| 2690 | continue; |
| 2691 | } |
| 2692 | float bottom = child.getTranslationY() + child.getActualHeight(); |
| 2693 | if (bottom > max) { |
| 2694 | max = bottom; |
| 2695 | } |
| 2696 | } |
Selim Cinek | d228115 | 2015-04-10 14:37:46 -0700 | [diff] [blame] | 2697 | return max + getStackTranslation(); |
Jorim Jaggi | e0640dd | 2014-08-05 23:12:40 +0200 | [diff] [blame] | 2698 | } |
| 2699 | |
Selim Cinek | 19c8c70 | 2014-08-25 22:09:19 +0200 | [diff] [blame] | 2700 | public void setPhoneStatusBar(PhoneStatusBar phoneStatusBar) { |
| 2701 | this.mPhoneStatusBar = phoneStatusBar; |
| 2702 | } |
| 2703 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2704 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 2705 | this.mGroupManager = groupManager; |
| 2706 | } |
| 2707 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2708 | public void onGoToKeyguard() { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 2709 | requestAnimateEverything(); |
| 2710 | } |
| 2711 | |
| 2712 | private void requestAnimateEverything() { |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2713 | if (mIsExpanded && mAnimationsEnabled) { |
| 2714 | mEverythingNeedsAnimation = true; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 2715 | mNeedsAnimation = true; |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2716 | requestChildrenUpdate(); |
| 2717 | } |
| 2718 | } |
| 2719 | |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 2720 | public boolean isBelowLastNotification(float touchX, float touchY) { |
Selim Cinek | abf60bb | 2015-02-20 17:36:10 +0100 | [diff] [blame] | 2721 | int childCount = getChildCount(); |
| 2722 | for (int i = childCount - 1; i >= 0; i--) { |
| 2723 | ExpandableView child = (ExpandableView) getChildAt(i); |
| 2724 | if (child.getVisibility() != View.GONE) { |
| 2725 | float childTop = child.getY(); |
| 2726 | if (childTop > touchY) { |
| 2727 | // we are above a notification entirely let's abort |
| 2728 | return false; |
| 2729 | } |
| 2730 | boolean belowChild = touchY > childTop + child.getActualHeight(); |
| 2731 | if (child == mDismissView) { |
| 2732 | if(!belowChild && !mDismissView.isOnEmptySpace(touchX - mDismissView.getX(), |
| 2733 | touchY - childTop)) { |
| 2734 | // We clicked on the dismiss button |
| 2735 | return false; |
| 2736 | } |
| 2737 | } else if (child == mEmptyShadeView) { |
| 2738 | // We arrived at the empty shade view, for which we accept all clicks |
| 2739 | return true; |
| 2740 | } else if (!belowChild){ |
| 2741 | // We are on a child |
| 2742 | return false; |
| 2743 | } |
| 2744 | } |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2745 | } |
Selim Cinek | 04fb258 | 2015-06-02 19:58:09 +0200 | [diff] [blame] | 2746 | return touchY > mTopPadding + mStackTranslation; |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2747 | } |
| 2748 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2749 | @Override |
| 2750 | public void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded) { |
Selim Cinek | 5bc852a | 2015-12-21 12:19:09 -0800 | [diff] [blame] | 2751 | boolean animated = mAnimationsEnabled && (mIsExpanded || changedRow.isPinned()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2752 | if (animated) { |
| 2753 | mExpandedGroupView = changedRow; |
| 2754 | mNeedsAnimation = true; |
| 2755 | } |
| 2756 | changedRow.setChildrenExpanded(expanded, animated); |
| 2757 | onHeightChanged(changedRow, false /* needsAnimation */); |
| 2758 | } |
| 2759 | |
| 2760 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2761 | public void onGroupCreatedFromChildren(NotificationGroupManager.NotificationGroup group) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 2762 | mPhoneStatusBar.requestNotificationUpdate(); |
| 2763 | } |
| 2764 | |
| 2765 | @Override |
| 2766 | public void onChildIsolationChanged() { |
| 2767 | mPhoneStatusBar.requestNotificationUpdate(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | public void generateChildOrderChangedEvent() { |
| 2771 | if (mIsExpanded && mAnimationsEnabled) { |
| 2772 | mGenerateChildOrderChangedEvent = true; |
| 2773 | mNeedsAnimation = true; |
| 2774 | requestChildrenUpdate(); |
| 2775 | } |
| 2776 | } |
| 2777 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2778 | public void runAfterAnimationFinished(Runnable runnable) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2779 | mAnimationFinishedRunnables.add(runnable); |
| 2780 | } |
| 2781 | |
| 2782 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 2783 | mHeadsUpManager = headsUpManager; |
| 2784 | mAmbientState.setHeadsUpManager(headsUpManager); |
| 2785 | } |
| 2786 | |
| 2787 | public void generateHeadsUpAnimation(ExpandableNotificationRow row, boolean isHeadsUp) { |
| 2788 | if (mAnimationsEnabled) { |
| 2789 | mHeadsUpChangeAnimations.add(new Pair<>(row, isHeadsUp)); |
| 2790 | mNeedsAnimation = true; |
| 2791 | requestChildrenUpdate(); |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | public void setShadeExpanded(boolean shadeExpanded) { |
| 2796 | mAmbientState.setShadeExpanded(shadeExpanded); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2797 | mStateAnimator.setShadeExpanded(shadeExpanded); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2800 | /** |
| 2801 | * Set the boundary for the bottom heads up position. The heads up will always be above this |
| 2802 | * position. |
| 2803 | * |
| 2804 | * @param height the height of the screen |
| 2805 | * @param bottomBarHeight the height of the bar on the bottom |
| 2806 | */ |
| 2807 | public void setHeadsUpBoundaries(int height, int bottomBarHeight) { |
| 2808 | mAmbientState.setMaxHeadsUpTranslation(height - bottomBarHeight); |
| 2809 | mStateAnimator.setHeadsUpAppearHeightBottom(height); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2810 | requestChildrenUpdate(); |
| 2811 | } |
| 2812 | |
| 2813 | public void setTrackingHeadsUp(boolean trackingHeadsUp) { |
| 2814 | mTrackingHeadsUp = trackingHeadsUp; |
| 2815 | } |
| 2816 | |
Selim Cinek | aac9325 | 2015-04-14 20:04:12 -0700 | [diff] [blame] | 2817 | public void setScrimController(ScrimController scrimController) { |
| 2818 | mScrimController = scrimController; |
| 2819 | } |
| 2820 | |
Selim Cinek | bbc580b | 2015-06-03 14:11:03 +0200 | [diff] [blame] | 2821 | public void forceNoOverlappingRendering(boolean force) { |
| 2822 | mForceNoOverlappingRendering = force; |
| 2823 | } |
| 2824 | |
| 2825 | @Override |
| 2826 | public boolean hasOverlappingRendering() { |
| 2827 | return !mForceNoOverlappingRendering && super.hasOverlappingRendering(); |
| 2828 | } |
| 2829 | |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 2830 | /** |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 2831 | * A listener that is notified when some child locations might have changed. |
| 2832 | */ |
| 2833 | public interface OnChildLocationsChangedListener { |
| 2834 | public void onChildLocationsChanged(NotificationStackScrollLayout stackScrollLayout); |
| 2835 | } |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2836 | |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2837 | /** |
Selim Cinek | 3a9c10a | 2014-10-28 14:21:10 +0100 | [diff] [blame] | 2838 | * A listener that is notified when the empty space below the notifications is clicked on |
| 2839 | */ |
| 2840 | public interface OnEmptySpaceClickListener { |
| 2841 | public void onEmptySpaceClicked(float x, float y); |
| 2842 | } |
| 2843 | |
| 2844 | /** |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2845 | * A listener that gets notified when the overscroll at the top has changed. |
| 2846 | */ |
| 2847 | public interface OnOverscrollTopChangedListener { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 2848 | |
| 2849 | /** |
| 2850 | * Notifies a listener that the overscroll has changed. |
| 2851 | * |
| 2852 | * @param amount the amount of overscroll, in pixels |
| 2853 | * @param isRubberbanded if true, this is a rubberbanded overscroll; if false, this is an |
| 2854 | * unrubberbanded motion to directly expand overscroll view (e.g expand |
| 2855 | * QS) |
| 2856 | */ |
| 2857 | public void onOverscrollTopChanged(float amount, boolean isRubberbanded); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 2858 | |
| 2859 | /** |
| 2860 | * Notify a listener that the scroller wants to escape from the scrolling motion and |
| 2861 | * start a fling animation to the expanded or collapsed overscroll view (e.g expand the QS) |
| 2862 | * |
| 2863 | * @param velocity The velocity that the Scroller had when over flinging |
| 2864 | * @param open Should the fling open or close the overscroll view. |
| 2865 | */ |
| 2866 | public void flingTopOverscroll(float velocity, boolean open); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 2867 | } |
| 2868 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 2869 | static class AnimationEvent { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 2870 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2871 | static AnimationFilter[] FILTERS = new AnimationFilter[] { |
| 2872 | |
| 2873 | // ANIMATION_TYPE_ADD |
| 2874 | new AnimationFilter() |
| 2875 | .animateAlpha() |
| 2876 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2877 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2878 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2879 | .animateZ() |
| 2880 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2881 | |
| 2882 | // ANIMATION_TYPE_REMOVE |
| 2883 | new AnimationFilter() |
| 2884 | .animateAlpha() |
| 2885 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2886 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2887 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2888 | .animateZ() |
| 2889 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2890 | |
| 2891 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 2892 | new AnimationFilter() |
| 2893 | .animateAlpha() |
| 2894 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2895 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2896 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2897 | .animateZ() |
| 2898 | .hasDelays(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2899 | |
| 2900 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 2901 | new AnimationFilter() |
| 2902 | .animateAlpha() |
| 2903 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2904 | .animateTopInset() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2905 | .animateY() |
| 2906 | .animateDimmed() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2907 | .animateZ(), |
| 2908 | |
| 2909 | // ANIMATION_TYPE_START_DRAG |
| 2910 | new AnimationFilter() |
| 2911 | .animateAlpha(), |
| 2912 | |
| 2913 | // ANIMATION_TYPE_SNAP_BACK |
| 2914 | new AnimationFilter() |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 2915 | .animateAlpha() |
| 2916 | .animateHeight(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2917 | |
| 2918 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 2919 | new AnimationFilter() |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2920 | .animateAlpha(), |
| 2921 | |
| 2922 | // ANIMATION_TYPE_DIMMED |
| 2923 | new AnimationFilter() |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 2924 | .animateY() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2925 | .animateDimmed(), |
| 2926 | |
| 2927 | // ANIMATION_TYPE_CHANGE_POSITION |
| 2928 | new AnimationFilter() |
| 2929 | .animateAlpha() |
| 2930 | .animateHeight() |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 2931 | .animateTopInset() |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2932 | .animateY() |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 2933 | .animateZ(), |
| 2934 | |
| 2935 | // ANIMATION_TYPE_DARK |
| 2936 | new AnimationFilter() |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 2937 | .animateDark() |
| 2938 | .hasDelays(), |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 2939 | |
| 2940 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 2941 | new AnimationFilter() |
| 2942 | .animateAlpha() |
| 2943 | .animateHeight() |
| 2944 | .animateTopInset() |
| 2945 | .animateY() |
| 2946 | .animateDimmed() |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2947 | .animateZ() |
| 2948 | .hasDelays(), |
| 2949 | |
| 2950 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 2951 | new AnimationFilter() |
| 2952 | .animateHideSensitive(), |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 2953 | |
| 2954 | // ANIMATION_TYPE_VIEW_RESIZE |
| 2955 | new AnimationFilter() |
| 2956 | .animateAlpha() |
| 2957 | .animateHeight() |
| 2958 | .animateTopInset() |
| 2959 | .animateY() |
| 2960 | .animateZ(), |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 2961 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2962 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
| 2963 | new AnimationFilter() |
| 2964 | .animateAlpha() |
| 2965 | .animateHeight() |
| 2966 | .animateTopInset() |
| 2967 | .animateY() |
| 2968 | .animateZ(), |
| 2969 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2970 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 2971 | new AnimationFilter() |
| 2972 | .animateAlpha() |
| 2973 | .animateHeight() |
| 2974 | .animateTopInset() |
| 2975 | .animateY() |
| 2976 | .animateZ(), |
| 2977 | |
| 2978 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 2979 | new AnimationFilter() |
| 2980 | .animateAlpha() |
| 2981 | .animateHeight() |
| 2982 | .animateTopInset() |
| 2983 | .animateY() |
| 2984 | .animateZ(), |
| 2985 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 2986 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 2987 | new AnimationFilter() |
| 2988 | .animateAlpha() |
| 2989 | .animateHeight() |
| 2990 | .animateTopInset() |
| 2991 | .animateY() |
| 2992 | .animateZ() |
| 2993 | .hasDelays(), |
| 2994 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 2995 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 2996 | new AnimationFilter() |
| 2997 | .animateAlpha() |
| 2998 | .animateHeight() |
| 2999 | .animateTopInset() |
| 3000 | .animateY() |
| 3001 | .animateZ(), |
| 3002 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3003 | // ANIMATION_TYPE_EVERYTHING |
| 3004 | new AnimationFilter() |
| 3005 | .animateAlpha() |
| 3006 | .animateDark() |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3007 | .animateDimmed() |
| 3008 | .animateHideSensitive() |
| 3009 | .animateHeight() |
| 3010 | .animateTopInset() |
| 3011 | .animateY() |
| 3012 | .animateZ(), |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3013 | }; |
| 3014 | |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3015 | static int[] LENGTHS = new int[] { |
| 3016 | |
| 3017 | // ANIMATION_TYPE_ADD |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3018 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3019 | |
| 3020 | // ANIMATION_TYPE_REMOVE |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3021 | StackStateAnimator.ANIMATION_DURATION_APPEAR_DISAPPEAR, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3022 | |
| 3023 | // ANIMATION_TYPE_REMOVE_SWIPED_OUT |
| 3024 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3025 | |
| 3026 | // ANIMATION_TYPE_TOP_PADDING_CHANGED |
| 3027 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3028 | |
| 3029 | // ANIMATION_TYPE_START_DRAG |
| 3030 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3031 | |
| 3032 | // ANIMATION_TYPE_SNAP_BACK |
| 3033 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3034 | |
| 3035 | // ANIMATION_TYPE_ACTIVATED_CHILD |
| 3036 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
| 3037 | |
| 3038 | // ANIMATION_TYPE_DIMMED |
| 3039 | StackStateAnimator.ANIMATION_DURATION_DIMMED_ACTIVATED, |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3040 | |
| 3041 | // ANIMATION_TYPE_CHANGE_POSITION |
| 3042 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3043 | |
| 3044 | // ANIMATION_TYPE_DARK |
| 3045 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3046 | |
| 3047 | // ANIMATION_TYPE_GO_TO_FULL_SHADE |
| 3048 | StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE, |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3049 | |
| 3050 | // ANIMATION_TYPE_HIDE_SENSITIVE |
| 3051 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3052 | |
| 3053 | // ANIMATION_TYPE_VIEW_RESIZE |
| 3054 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3055 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3056 | // ANIMATION_TYPE_GROUP_EXPANSION_CHANGED |
Selim Cinek | 9969559 | 2016-01-12 17:51:35 -0800 | [diff] [blame] | 3057 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3058 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3059 | // ANIMATION_TYPE_HEADS_UP_APPEAR |
| 3060 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_APPEAR, |
| 3061 | |
| 3062 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR |
| 3063 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 3064 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3065 | // ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK |
| 3066 | StackStateAnimator.ANIMATION_DURATION_HEADS_UP_DISAPPEAR, |
| 3067 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3068 | // ANIMATION_TYPE_HEADS_UP_OTHER |
| 3069 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
| 3070 | |
Selim Cinek | d9acca5 | 2014-09-01 22:33:25 +0200 | [diff] [blame] | 3071 | // ANIMATION_TYPE_EVERYTHING |
| 3072 | StackStateAnimator.ANIMATION_DURATION_STANDARD, |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3073 | }; |
| 3074 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3075 | static final int ANIMATION_TYPE_ADD = 0; |
| 3076 | static final int ANIMATION_TYPE_REMOVE = 1; |
| 3077 | static final int ANIMATION_TYPE_REMOVE_SWIPED_OUT = 2; |
| 3078 | static final int ANIMATION_TYPE_TOP_PADDING_CHANGED = 3; |
| 3079 | static final int ANIMATION_TYPE_START_DRAG = 4; |
| 3080 | static final int ANIMATION_TYPE_SNAP_BACK = 5; |
| 3081 | static final int ANIMATION_TYPE_ACTIVATED_CHILD = 6; |
| 3082 | static final int ANIMATION_TYPE_DIMMED = 7; |
| 3083 | static final int ANIMATION_TYPE_CHANGE_POSITION = 8; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 3084 | static final int ANIMATION_TYPE_DARK = 9; |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3085 | static final int ANIMATION_TYPE_GO_TO_FULL_SHADE = 10; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 3086 | static final int ANIMATION_TYPE_HIDE_SENSITIVE = 11; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 3087 | static final int ANIMATION_TYPE_VIEW_RESIZE = 12; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 3088 | static final int ANIMATION_TYPE_GROUP_EXPANSION_CHANGED = 13; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 3089 | static final int ANIMATION_TYPE_HEADS_UP_APPEAR = 14; |
| 3090 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR = 15; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 3091 | static final int ANIMATION_TYPE_HEADS_UP_DISAPPEAR_CLICK = 16; |
| 3092 | static final int ANIMATION_TYPE_HEADS_UP_OTHER = 17; |
| 3093 | static final int ANIMATION_TYPE_EVERYTHING = 18; |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3094 | |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3095 | static final int DARK_ANIMATION_ORIGIN_INDEX_ABOVE = -1; |
| 3096 | static final int DARK_ANIMATION_ORIGIN_INDEX_BELOW = -2; |
| 3097 | |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3098 | final long eventStartTime; |
| 3099 | final View changingView; |
| 3100 | final int animationType; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3101 | final AnimationFilter filter; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3102 | final long length; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 3103 | View viewAfterChangingView; |
Jorim Jaggi | 2a5e452 | 2014-11-24 21:45:20 +0100 | [diff] [blame] | 3104 | int darkAnimationOriginIndex; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 3105 | boolean headsUpFromBottom; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3106 | |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 3107 | AnimationEvent(View view, int type) { |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3108 | this(view, type, LENGTHS[type]); |
| 3109 | } |
| 3110 | |
| 3111 | AnimationEvent(View view, int type, long length) { |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3112 | eventStartTime = AnimationUtils.currentAnimationTimeMillis(); |
| 3113 | changingView = view; |
| 3114 | animationType = type; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 3115 | filter = FILTERS[type]; |
Jorim Jaggi | ff9c9c4 | 2014-08-01 05:36:22 +0200 | [diff] [blame] | 3116 | this.length = length; |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | /** |
| 3120 | * Combines the length of several animation events into a single value. |
| 3121 | * |
| 3122 | * @param events The events of the lengths to combine. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3123 | * @return The combined length. Depending on the event types, this might be the maximum of |
| 3124 | * all events or the length of a specific event. |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3125 | */ |
| 3126 | static long combineLength(ArrayList<AnimationEvent> events) { |
| 3127 | long length = 0; |
| 3128 | int size = events.size(); |
| 3129 | for (int i = 0; i < size; i++) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 3130 | AnimationEvent event = events.get(i); |
| 3131 | length = Math.max(length, event.length); |
| 3132 | if (event.animationType == ANIMATION_TYPE_GO_TO_FULL_SHADE) { |
| 3133 | return event.length; |
| 3134 | } |
Jorim Jaggi | 5aa045c | 2014-05-07 21:42:40 +0200 | [diff] [blame] | 3135 | } |
| 3136 | return length; |
Selim Cinek | 572bbd4 | 2014-04-25 16:43:27 +0200 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 3140 | } |