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